1, log4j is an Apache open source project, can be configured flexibly through a configuration file, without the need to modify the application code.
2, LOG4J has three main components:
- Logger: Writes log information to one or more output sources according to the format specified in the layout;
- Output Source: Can be a console, a text file, an XML file, or a socket, or even write to the Windows event log or send it by e-mail;
- Layout: All classes that inherit the layout class define the layout of the log information, the so-called layout is the format of the log information.
3, there are 5 kinds of log levels in log4j:
FATAL: Output debug information for fatal error level;
Error: Output debug information at the wrong level;
WARN: Debug information for output warning level;
Info: Debug information at the output prompt level;
Debug: Output general debugging information;
4, log management in the process of running the program to provide accurate runtime context to facilitate developers to find bug;log information can be exported to different places; In addition to playing its role in the development process, a powerful enough logging development package can be used as an audit tool.
5, log information embedded in the Java code, the runtime has a certain impact on efficiency, occupy resources, increase the cost of code and unnecessary output. Therefore: the release phase as far as possible to close unnecessary debug information log, to improve the efficiency of the program run.
Java EE log4j