在项目的 pom.xml
中,我看到如下所示的依赖项
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
有人可以告诉我 slf4j-log4j12
和 log4j
之间有什么区别吗?
最佳答案
Log4j 1.2
slf4j-log4j12
提供了 SLF4J 和 Log4j 1.2 之间的桥梁,以便 SLF4J 知道如何使用 Log4j 进行日志记录。
您正在使用 Log4j 1.2。该版本的绑定(bind)由 SLF4J 项目维护。这是来自 the SLF4J docs 的摘要:
SLF4J supports various logging frameworks. The SLF4J distribution ships with several jar files referred to as "SLF4J bindings", with each binding corresponding to a supported framework.
slf4j-log4j12-1.7.28.jar
Binding for log4j version 1.2, a widely used logging framework. You also need to place log4j.jar on your class path.
Log4j 2
如果您使用的是 Log4j 2 或更高版本,则需要与 slf4j-log4j12
不同的绑定(bind) JAR。该绑定(bind)由 Log4j 项目维护。 According to the Log4j docs :
The Log4j 2 SLF4J Binding allows applications coded to the SLF4J API to use Log4j 2 as the implementation.
如果您希望 SLF4J 将日志记录路由到 Log4j,则必须提供这两个依赖项。同样,来自 Log4j 2 文档:
Simply include the Log4j 2 SLF4J Binding jar along with the Log4j 2 jars and SLF4J API jar to cause all SLF4J logging to be handled by Log4j 2.
关于java - slf4j-log4j12 与 log4j 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47574644/