Reputation: 1175
I have an app using Log4j2 and so far I have no issues. This morning, I added a 3rd party library which , in turn, uses logback for logging.
Now I see this error:
Error loading configuration Cause: org.apache.logging.slf4j.Log4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
How do I fix this error?
My app has the following dependencies:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.4.1</version>
</dependency>
Whereas the 3rd party library uses the following:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.12</version>
</dependency>
Is it possible to have both log4j2 and logback configured at the same time? How do I fix the configuration?
Upvotes: 2
Views: 7278
Reputation: 9141
Logbook uses SLF4J as its API. You cannot have both Log4j-slf4j-impl and the Logback jars. If you do not want to use Logback then where you have the dependency declared for the 3rd party library you need to add exclusions for logback-classic and logback-core.
Upvotes: 4