Log4j and South

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

[log4j and South]

1. Background introduction

Log4j may be the most commonly used log generation dependent jar package. Of course, there are other log generation jar packages, such as log4j2, and so on. South is system out. Print / println is our common console printing method.

Log4j is an open source project of Apache. By using log4j, we can control that the destinations of log information transmission are console, files, GUI components, even socket server, NT event recorder, UNIX syslog daemon, etc; We can also control the output format of each log; By defining the level of each log information, we can control the log generation process in more detail. The most interesting thing is that these can be flexibly configured through a configuration file without modifying the application code.

2. Knowledge analysis

Log4j has three main components: loggers, Appenders, and layouts. It can be simply understood here as log category, where the log is to be output and in what form.

Loggers components are divided into five levels in this system: debug, info, warn, error and fatal.

These five levels are in order. Debug < info < warn < error < fatal are used to specify the importance of this log information respectively.

Log4j has a rule: only log information with a level not lower than the set level is output.

Appenders configures log information output.

Layouts sets the format of log output. Layouts provides four log output styles, such as HTML style, freely specified style, style containing log level and information, and style containing log time, thread, category and other information.

3. Why not use south

We saw that the configuration file of log4j has the relevant configuration output to the file, which is the difference between it and south, and it is also the key point why we use log, because when we find the log information, we can check it in the corresponding log file, and the previous log information will not be lost due to factors such as program shutdown. If it is south, the program will be closed, The information is lost. If we want to see the error report, we must run the program again.

4. Expand thinking

We use XML to configure log4j

The log and South information are customized by us, which can be input into Is there only our customized information in the log file?

5. References

http://www.open-open.com/lib/view/open1393488356958.html

Ppt link: https://ptteng.github.io/PPT/PPT-java/java-task1-log4jandsout.html#/

Actual operation: https://v.qq.com/x/page/j05584bvkjn.html

Author: heavy bell link: https://www.jianshu.com/p/398ba7499db9 Source: the copyright of Jianshu Jianshu belongs to the author. Please contact the author for authorization and indicate the source for any form of reprint.

For more information, you can join the IT communication group 565734203 to discuss and communicate with you

Here is the skill tree · it Academy: nofollow "> https://www.jnshu.com , beginners switch to the gathering place of the Internet

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>