Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

We Are Going To Discuss About Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j. So lets Start this Java Article.

Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

  1. Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

    According to Spring documentation (as pointed out by Simon), we want to exclude the “spring-boot-starter-logging” module from all libraries, not just from “spring-boot-starter-web”.

  2. org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

    According to Spring documentation (as pointed out by Simon), we want to exclude the “spring-boot-starter-logging” module from all libraries, not just from “spring-boot-starter-web”.

Solution 1

According to Spring documentation (as pointed out by Simon), we want to exclude the “spring-boot-starter-logging” module from all libraries, not just from “spring-boot-starter-web”.

configurations {
    ...
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

…instead of…

dependencies {
    ...
    implementation('org.springframework.boot:spring-boot-starter') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

I myself had the same problem and solved it with this solution.

Advertisements

Original Author Of This Content

Solution 2

Spring boot 2.3.0.RELEASE version, support Log4j2 natively, for logging configuration if it is on the classpath. In this case, you can simply remove other log4j dependencies.

In other case, if you use the starters for assembling dependencies, you have to exclude Logback and then include log4j 2 instead:

You can do like that with Gradle:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-log4j2'
}

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

Or with Maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

More information on the official documentation: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-log4j-for-logging

Advertisements

Original Author Of This Content

Solution 3

I excluded spring boot logging from build.gradle but issue was still occurring. It got resolved by removing org.apache.logging.log4j/log4j-slf4j-impl/2.12.1 from .classpath

Advertisements

Original Author Of This Content

Solution 4

From the error logs decide which project to exclude.

e.g for a error msg like this: Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j
I’ve used the gradle exclude:

configurations.all { exclude group: ‘org.apache.logging.log4j’

}

Advertisements

Original Author Of This Content

Conclusion

Advertisements

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment