slf4j和log4j2整合报错,绑定失败

slf4j和log4j2整合报错

今天在整合的时候,报以下错误:

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/F:/IntelliJ%20IDEA%202020.1.3/plugins/maven/lib/maven3/maven-repo/org/apache/logging/log4j/log4j-slf4j-impl/2.11.1/log4j-slf4j-impl-2.11.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.

后来更换了slf4j的版本就可以了,应该是版本不匹配导致的问题,因为我原来的maven依赖中slf4j采用的是最新的版本,但是运行之后就报错了,所以采用以下版本进行替换。

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.11.1</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
</dependency>

log4j-slf4j-impl包含了log4j2的适配器和具体实现,所以整合slf4j和log4j2只需要导入这两个就行了。

保持对优秀的热情
原文地址:https://www.cnblogs.com/luckforefforts/p/13807364.html