The log system is needed for server development recently, so the log framework under Apache is studied.
The current log system, supported by the language has C++,php,.net,java. Of course I use the Java server, choose to use log4j bar. But suddenly found that log4j 2 is more interesting, the official website also mentions that there is a performance ratio of 1. X has a bigger boost, and there are a lot of articles on log4j online.
Then let's learn the log4j 2.
As for personal choices, I sometimes don't like using debuggers very much. One reason is that the details of its complex data structures and control processes require me to think about it, especially if one-step tracking is more troublesome, and it takes more time to click Statements and think.
With the output, it takes less time to decide where to put the printed statement, rather than to think about the key parts of the single step Code and use the shortcut keys to step through the debugging. More importantly, the debug statement is left in the program, and the debugging session is short-lived.
Logging does have its drawbacks. It can make the application slower. If it is too detailed, it may cause scrolling to go out of bounds and not see all of it. To mitigate these effects, the log4j is designed to be reliable, fast and scalable
Log4j™2
The log4j 1.x has been widely adopted and used in many applications. However, after years of development has slowed down. It becomes more difficult to maintain because it requires strict adherence to the very old version of Java. Its approach, slf4j/logback to the framework many needs to be improved. So, why is there log4j 2? Here are a few reasons.
1.LOG4J 2 is designed as an audit log framework. log4j1.x and Logback are reconfigured when they lose events. Log4j 2 not. In the Logback appenders, the exception application is absolutely invisible. In log4j 2 appenders can be configured to allow anomalies to seep into the application
2.log4j 2 contains the next generation unlocked asynchronous loggers on the Lmax disruptor library basis. In multithreaded situations, asynchronous loggers has a 10 times-fold throughput and a lower latency than the log4j1.x and logback amplitude.
3.LOG4J 2 incorporates a plug-in system that adds new Appenders, Filters, Layouts, lookups, and pattern converters more easily.
4. Because the plug-in system configuration is simple. The class name is not required in the Entries configuration.
5. Supports the Message object. The message allows for interesting and complex structure support, which is effectively manipulated by the log system pass. Users can freely create their own message types and write custom Layouts, Filters, lookups and manipulate them.
6.LOG4J's 1.x support on the Appender filter. Logback Join turbofilters allows filtering by an event that is handled by a logger. LOG4J 2 support can be configured to handle events before processing by a logger because they are handled by a logger or appenders.
7. Many logback Appender do not accept layouts, and only send data in a fixed format. Most of the log4j 2Appenders accepts layouts, allowing data to be transmitted in any format that is required.
8. Returns a string in the log4j 1.x and logback layouts. This leads to issues discussed in the Logback encoder. Log4j 2 takes a simpler approach, and the layout always returns a byte array. This has the advantage that it means they can be used in almost any append program, rather than just writing to OutputStream.
9. The system log Appender supports both TCP and UDP as well as BSD-enabled system logs and RFC5424 formats.
10.LOG4J's 2 leverages the benefits of concurrency support for Java 5 to lock at the lowest possible level. The deadlock problem is already known in the log4j 1.x. Many of these are fixed logback but many logback classes still need to be synchronized at fairly high levels.
Architecture
Logger
Loggers is created by calling Logmanager.getlogger. The logger itself does not perform any direct actions. It's just a name, and it's about loggerconfig. It extends the Abstractlogger and implements the required methods. Configuration modification logger can be associated with different loggerconfig, resulting in the need to modify its behavior.
Calling the Logmanager.getlogger method with the same name always returns a reference to the exact same logger object.
For example, in
Logger X =
X and y refer to the exact same logger object, which can be used = =.
The environment configuration of log4j is usually when the application is initialized. The preferred method is by reading the configuration file. This has already been discussed in the configuration section.
Log4j can easily be named for logger software components. This can be done by instantiating a logger in each class with the fully qualified name of the same class as the logger name (such as Tl.lan or Org.lan). This is an effective and straightforward way to define logger.
As the log output with the name generating the log logger, this naming strategy can easily identify the source of the log information. Log4j is not limited to as many logger as possible. Developers are free to name logger as needed.
It is common to name logger with class names, and the convenient way Logmanager.getlogger (Object.class) is set to automatically use the fully qualified class name of the calling class as logger.
The class where they are located to name logger seems to be the best strategy known at the moment.
APACHE log4j? 2