log

http://logging.apache.org/log4j/2.x/maven-artifacts.html

Log interface library

common-logging

common-logging provides a unified interface for many specific log implementation libraries. It allows binding to arbitrary logging libraries at runtime . But since it uses the ClassLoader to find and load the underlying logging library, this causes frameworks like OSGi to not work properly because its different plugins use their own ClassLoader. This mechanism of OSGi ensures that plugins are independent of each other, but makes Apache Common-Logging not work.

Detailed reference: http://commons.apache.org/proper/commons-logging/

slf4j

The Simple Logging Facade for Java is not a specific logging solution, it only serves a variety of logging systems, allowing end users to use the logging system they want when deploying their applications .

In fact, the core API provided by SLF4J is some interfaces and a factory class of LoggerFactory. When using SLF4J, there is no need to specify in code or in a configuration file which specific logging system you intend to use. SLF4J provides a unified log recording interface, as long as it is recorded according to the method provided, the final log format, record level, output method, etc. are realized by the configuration of the specific log system, so the log system can be flexibly switched in the application.

Detailed reference: http://www.slf4j.org/

common-logging compared to slf4j

common-logging automatically finds the log library actually used through the dynamic search mechanism at runtime, while sflfj determines the log library used at the time of deployment. Currently slf4j is used more.

 When using Commons Logging, we often see the following methods written:

if (logger.isDebugEnabled()) {

    logger.info("Loading XML bean definitions from " + encodedResource.getResource());

}

The judgment logic of isDebugEnabled() exists to avoid redundant string splicing, that is, if there is no isDebugEnabled() judgment, even if the current log level is ERROR, when it encounters the logger.info() call, it will first splicing The string of the log message, and then enter the method, only to find that this log statement does not need to be printed. And this redundant splicing not only wastes redundant CPU operations, but also increases the burden of GC. SLF4J provides the following ways to solve this problem:

logger.info("Loading XML bean definitions from {}", encodedResource.getResource());

log implementation library

java.util.logging

The log library implementation that comes with Java 1.4 and above. Compared to log4j, it has a little less functionality.

 

log4j

Log4j is a very feature-rich Java logging library implementation under Apache. By using Log4j, we can control the destination of log information delivery is console, file, GUI component, even socket server, NT event logger, UNIX Syslog daemon, etc.; users can also control the output format of each log ; it has two major versions, 1.2 and 2.x. 2.x has made many improvements on the basis of 1.x, absorbed many advantages in Logback, and solved some problems in Logback.

Detailed reference: http://logging.apache.org/log4j/1.2/ and http://logging.apache.org/log4j/2.x/

 

Logback

Logback emerged as a replacement for Log4j and is superior to Log4j in many ways. The author also wrote an article describing why to migrate from Log4j to Logback, see: http://logback.qos.ch/reasonsToSwitch.html

Detailed reference: http://logback.qos.ch/ 

 

Log4j vs Logback

Compared with Log4j1.x, Logback is better in all aspects, and the choice between them is definitely Logback. But because of the major improvements of Log4j2.x, I haven't had time to carefully analyze and compare the choice between Log4j2.x and Logback. I will leave a question for the time being, and I will add it after analysis. However, there is not much difference for general J2EE applications.

 

References:

1.   http://liuzidong.iteye.com/blog/776072    Java Logging Framework: SLF4J, Apache Common-Logging, Log4J and Logback

2.   http://www.blogjava.net/lhulcn618/articles/16996.html  Log4j vs java.util.logging

3.   http://www.cnblogs.com/Leo_wl/p/3417215.html   Comparison of Log4j, Log4j 2, Logback, SFL4J, JUL, JCL

=========

additional materials:

The difference between log4j and log4j2:

http://blog.csdn.net/fangaohua200/article/details/53561718

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326032527&siteId=291194637
log
log