as the open source framework is becoming richer, many of the log components used by open source frameworks are different. exist in a project, different versions, different frameworks coexist.
There are some standard common interface, standard implementation, the existence of various bridges, let me set up the relationship between these frameworks.
slf4j Relationship to the old log frame
slf4j equals commons-logging, is a common entry for various log implementations, depending on which jar exists in the classpath to determine the specific log implementation library. Logback-classic (default Logback implementation)
Slf4j-jcl.jar (Apache Commons logging)
Slf4j-logj12.jar (log4j 1.2.4)
slf4j-jdk14 (java.util.logging)
go to SLFJ for all log calls to a third-party class library or old code that uses the legacy log API Jcl-over-slf4j.jar/jcl104-over-slf4j:apache Commons Logging 1.1.1/1.0.4, can be replaced directly.
log4j-over-slf4j.jar:log4j, the direct replacement can be.
JUL-TO-SLF4J:JDK logging, you need to call Slf4jbridgehandler.install () at the beginning of the program to register the Listener reference Juloverslf4jprocessor, The bean can be defined in Applicationcontext.xml for initialization. Note that the original log4j.properites will expire, and the Logback website provides converters that support conversion from log4j.properties to Logback.xml.
How to configure Logback
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.api.version}</version>
</dependency>
<!--logback--
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.6</version>
</dependency>
compatible with legacy logging frameworks
SLF4J support for log4j 1 and Apache Commons logging is provided by LOG4J implementations that implement Commons and Apache logging slf4j interfaces. How to use it
To fetch a reference to the jar package for log4j and Apache Commons logging
Introduce the implementation package of the corresponding interface of SLF4J.
Remove reference
If your system is directly using the log4j or Apache Commons logging framework, you can simply remove the reference to them. If you are referring to a third-party package that references log4j or Apache Commons Logging, you can use the <exclusions> tag to remove references to them as follows:
<Dependency>
<groupId>Org.springframework.ldap</groupId>
<Artifactid>Spring-ldap-core</Artifactid>
<Exclusions>
<exclusion>
<Artifactid>commons-logging</Artifactid>
<groupId>commons-logging</groupId>
</exclusion>
</Exclusions>
</Dependency>
Logback.xml
<?XML version= "1.0" encoding= "UTF-8"?>
<ConfigurationScan= "true"Scanperiod= "Seconds">
<!--Appendar Explanation: Http://logback.qos.ch/manual/appenders.html#RollingFileAppender -
<Appendername= "FILE"class= "Ch.qos.logback.core.rolling.RollingFileAppender">
<!--Current log file name -
<file>Ldap-pwd.log</file>
<Rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--non-day log file compression backup for Archive/ldap-pwd.2014-08-10.zip -
<Filenamepattern>Archive/ldap-pwd.%d{yyyy-mm-dd}.zip</Filenamepattern>
<!--backup files that are older than 30 days are deleted -
<maxhistory>30</maxhistory>
</Rollingpolicy>
<Layoutclass= "Ch.qos.logback.classic.PatternLayout">
<!--format Description: Http://logback.qos.ch/manual/layouts.html#ClassicPatternLayout -
<Pattern>%d [%thread]%-5level%40logger{40}-%msg%n</Pattern>
</Layout>
</Appender>
<Loggername= "Cn.justfly.training.logging" Level= "Info" />
<Root Level= "Warn">
<Appender-refref= "FILE" />
</Root>
</Configuration>
The Java log component of those broken things