neves
neves

Reputation: 39443

Java log: failed to load slf4j but I'm using log4j2. How to fix?

When I run my jar file, I get the following error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

The problem is that I'm not using slf4j, I'm using log4j2. It is used by a dependency. Maven correctly includes org.slf4j:slf4j-api as a transitive dependency of a library that I'm using.

How do I get rid of this warning? I do not even want to log problems with this dependency.

Upvotes: 2

Views: 3553

Answers (1)

neves
neves

Reputation: 39443

I've solved it with this dependency:

<dependency>
    <groupId>org.apache.logging.log4j</groupId> 
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.11.0</version>
</dependency>

This will add the log4j2 as the implementation of slf4j api. I can even display log events of the dependency if I want.

Upvotes: 7

Related Questions