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

The error message “caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j” occurs when both the log4j-slf4j-impl and log4j-to-slf4j dependencies are present in your project. These two dependencies provide the same functionality and are incompatible with each other.

To resolve this issue, you need to exclude either the log4j-slf4j-impl or log4j-to-slf4j dependency from your project, depending on which one is causing the conflict. You can do this by adding an exclusion configuration in your project’s build file (e.g., pom.xml for Maven projects).

Here is an example of how to exclude the log4j-slf4j-impl dependency using Maven:

        
            <dependencies>
                <dependency>
                    <groupId>your.group.id</groupId>
                    <artifactId>your.artifact.id</artifactId>
                    <version>your.version</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.apache.logging.log4j</groupId>
                            <artifactId>log4j-slf4j-impl</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        
    

By excluding the log4j-slf4j-impl dependency, your project will only use the log4j-to-slf4j dependency for logging, and the conflict should be resolved.

Same cateogry post

Leave a comment