简体   繁体   English

如何解决 log4j2 和 logback 冲突?

[英]how to solve the log4j2 and the logback confliction?

I tried every way,just still dont works,where is the confiction,I just tried every method from the internet ,i got so frastrated!!!各种方法都试过了,还是不行,哪里有,网上的各种方法都试过了,好烦!!!

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/apache-maven/localrep/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/apache-maven/localrep/org/apache/logging/log4j/log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Logging system failed to initialize using configuration from 'classpath:log4j2.xml'
java.lang.IllegalStateException: Logback configuration error detected: 
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

You can use the Maven dependency plugin to find where dependencies are coming from.您可以使用 Maven 依赖插件来查找依赖的来源。

$ mvn dependency:tree -Dincludes=*:logback-classic:*,*:log4j-slf4j-impl:*
...
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ my-project ---
[INFO] com.example:my-project:jar:1.0-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-actuator:jar:2.2.6.RELEASE:compile
[INFO]    \- org.springframework.boot:spring-boot-starter:jar:2.2.6.RELEASE:compile
[INFO]       \- org.springframework.boot:spring-boot-starter-logging:jar:2.2.6.RELEASE:compile
[INFO]          \- ch.qos.logback:logback-classic:jar:1.2.3:compile
...

If you want to exclude spring-boot-starter-logging you need to add an explicit spring-boot-starter first.如果要排除spring-boot-starter-logging ,则需要先添加显式spring-boot-starter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM