Java Error: log4j2 - Failed to load class “org.slf4j.impl.StaticLoggerBinder”

When I run my Java project, I’m getting the following error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
SLF4J: Defaulting to no-operation (NOP) logger implementation

How do I fix this message?

These are the logger imports in my project:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

These are the relevant dependencies in my Maven:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.26</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.7</version>
</dependency>
  1. Add SLF4J Bridge

Add SLF4J Bridge

You are getting this error because the project you are trying to build is using the SLF4J API (which is a facade or abstraction of various logging framework) but doesn’t specify an actual implementation. To fix this, you’ll need the Log4j2-SLF4J Binding.

You can easily resolve this warning by adding the SLF4J Bridge dependency to your pom.xml:

<!-- SLF4J Bridge -->
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.7</version>
</dependency>

<!-- log4j core -->
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.7</version>
</dependency>

You can also remove the slf4j-api from your pom.xml because it is not needed.

A note regarding Binding version:

There are two SLF4J to Log4j Adapters and you should use the right one due to broken backward compatibility:

  • log4j-slf4j-impl: Use with SLF4J 1.7.x releases or older.
  • log4j-slf4j18-impl: Use with SLF4J 1.8.x releases or newer.

Speak Your Mind