日志框架大致可以分为两类,一类是日志门面(Facade)(Apache Commons-logging 也被称作 Jakarta Commons-Logging(JCL)、slf4j、Log4j-api),定义日志的抽象接口;另一类是日志实现(JUL,log4j,log4j2,logback),负责真正地处理日志。
Legacy version of Log4J logging framework. Log4J 1 has reached its end of life and is no longer officially supported. It is recommended to migrate to Log4J 2.
To start using the Logback, you need to add the
logback-classicdependency to the classpath:<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency>This single dependency is enough, as it will transitively pull in the
logback-coreandslf4j-apidependencies.If no custom configuration is defined, Logback provides a simple, automatic configuration on its own. By default, this ensures that log statements are printed to the console at DEBUG level.
@Log (and friends)@Log4j2
Creates private static final [org.apache.logging.log4j.Logger](<https://logging.apache.org/log4j/2.0/log4j-api/apidocs/org/apache/logging/log4j/Logger.html>) log = [org.apache.logging.log4j.LogManager.getLogger](<https://logging.apache.org/log4j/2.0/log4j-api/apidocs/org/apache/logging/log4j/LogManager.html#getLogger(java.lang.Class)>)(LogExample.class);
@Slf4j
Creates private static final [org.slf4j.Logger](<https://www.slf4j.org/api/org/slf4j/Logger.html>) log = [org.slf4j.LoggerFactory.getLogger](<https://www.slf4j.org/api/org/slf4j/LoggerFactory.html#getLogger(java.lang.Class)>)(LogExample.class);