The relationship between slf4j and Log4j, log4j2, etc.

Insert picture description hereInterface-oriented programming tells us to use a specific log system, which is inconvenient to upgrade. The log system in the imported jar may be different and cannot be used. Therefore, a unified log interface is required that can be compatible with various log systems. That is slf4j.

slf4j provides an interface for users to use. However, no implementation is provided, and users have to choose and configure the desired log system in their own projects. As long as slf4j is used in the imported jars, there will be no compatibility issues.

The specific method of use is to use a bridge between slf4j and a specific log system to implement the spi interface of slf4j, while using a specific log system.

Give several plans:

1 、 slf4j + log4j

log4j core jar package: log4j-1.2.17.jar

slf4j core jar package: slf4j-api-1.6.4.jar

The bridging package of slf4j and log4j: slf4j-log4j12-1.6.1.jar, the function of this package is to use the api of slf4j, but the underlying implementation is based on log4j

2、slf4j+log4j2

log4j2 core jar package: log4j-api-2.7.jar and log4j-core-2.7.jar

slf4j core jar package: slf4j-api-1.6.4.jar

The bridge package of slf4j and log4j2: log4j-slf4j-impl-2.7.jar, the function of this package is to use the api of slf4j, but the underlying implementation is based on log4j2

If you use springmvc, you also need to increase the log4j-web-*.jar package;
if you want to use the asynchronous output method of log4j2, you also need to increase

    <dependency>
      <groupId>com.lmax</groupId>
      <artifactId>disruptor</artifactId>
      <version>3.4.2</version>
    </dependency>

Guess you like

Origin blog.csdn.net/u011930054/article/details/103680724