score:68

Accepted answer

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.

score:0

even after correcting classpath, i had the same problem in sts and gradle 'refresh all' solved it.

score:0

the best way to solve this would be to run gradle dependencies, and identify where the log4j-to-slf4j is coming from, and then exclude this module in build.gradle

score:1

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

score:2

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'

}

score:30

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


Related Query

More Query from same tag