SLF4J

Solving slf4j: Failed to load class “org.slf4j.impl.StaticLoggerBinder”

In this post, we feature a comprehensive article about how to solve the error slf4j: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.

You can also check this tutorial in the following video:

Solving slf4j: Failed to load class “org.slf4j.impl.StaticLoggerBinder” – Video

1. Introduction

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j). This allows the end-user to plug in the desired logging framework at deployment time.

slf4j: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

SLF4J facilitates your code to make logging calls without binding to a specific logging implementation. This comes real handy for libraries where it is not desired to hard bind the API to a particular logging framework; the program might be using another logging implementation.

2. The slf4j: Failed to load class “org.slf4j.impl.StaticLoggerBinder” Error

While working with SLF4J, you need to provide the following three components (read jars):

  1. SLF4J API (slf4j-api.jar) – This lets you make logging calls to SLF4J’s org.slf4j.Logger in your code (and not a specific logging implementation thus introducing logging abstraction in your code).
  2. SLF4J Binding – This is either slf4j-log4j12.jar (for log4j logging), slf4j-jdk14.jar (for Java logging), slf4j-jcl.jar (if you’re using Commons logging) or logback-classic.jar (for logback logging). With the correct binding jar, SLF4J is able to interface between slf4j-api and underlying logging implementation.
  3. Underlying Logging Implementation – Here you provide the underlying logging library which will actually do the logging for your program. SLF4J will delegate logging calls to this library.

Among all these components, if you miss the 2nd one, then you will run into the Failed to load class “org.slf4j.impl.StaticLoggerBinder” message and the org.slf4j.impl.StaticLoggerBinder is found in any of the SLF4J’s binding jar.

Let’s try some code and see how we can fix this.

3. Example of the error Failed to load class “org.slf4j.impl.StaticLoggerBinder” in slf4j

3.1 Create a Maven Project

We will create a bare minimum Maven project. Once you have the Maven installed and running on your machine, issue the following command from the command line.

1
mvn archetype:generate -DgroupId=com.javacodegeeks -DartifactId=slf4-spring-boot -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

In this example, Maven will manage dependencies for us and we don’t need to download any jars explicitly.

3.2 Add Maven Dependencies

Add dependency just for slf4j-api.

pom.xml

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.javacodegeeks</groupId>
  <artifactId>slf4jconfig-javalogging</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
 
  <name>slf4jconfig-javalogging</name>
 
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
 
  <dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
  </dependencies>
</project>

3.3 Test Class

HelloJavaLogging.java

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
package com.javacodegeeks.slf4jconfig_javalogging;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
/**
 * HelloJavaLogging!
 *
 */
public class HelloJavaLogging
{
    public static void main( String[] args )
    {
        Logger logger = LoggerFactory.getLogger(HelloJavaLogging.class);
        logger.info("This is how you configure Java Logging with SLF4J");
    }
}

Run the code.

Output

1
2
3
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.

It seems like we missed the binding jar for SLF4J and Java Logging. Let’s add slf4j-jdk14 jar file and see if it solves the problem.

Add the following lines in your pom.xml:

1
2
3
4
5
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>1.7.25</version>
</dependency>

Note: We don’t need to provide the underlying logging framework’s jar in this case as we are using Java Logging. The implementation is provided in JDK.

Let’s re-run the code.

Output

1
2
May 03, 2017 8:10:40 PM com.javacodegeeks.slf4jconfig_javalogging.HelloJavaLogging main
INFO: This is how you configure Java Logging with SLF4J

Finally, we got the output we desired.

4. slf4j: Failed to load class “org.slf4j.impl.StaticLoggerBinder” – Summary

Remember, the absence of SLF4J Binding runs into Failed to load class “org.slf4j.impl.StaticLoggerBinder” Error.

Notes:

  1. As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.
  2. As of SLF4J version 1.8.0, the static binder mechanism will be deprecated. StaticLoggerBinder is likely to be removed in future releases of SLF4J.

5. Download the Eclipse Project

That was an article about how to solve the error slf4j: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

Download
You can download the full source code of this example here: Solving slf4j: Failed to load class “org.slf4j.impl.StaticLoggerBinder”

Last updated on Feb. 27th, 2022

Mayank Gupta

Senior JEE developer with experience in large scale IT projects, especially in the telecommunications and financial services sectors. Mayank has been designing and building J2EE applications since 2007. Fascinated by all forms of software development; keen to explore upcoming areas of technology like AI, machine learning, blockchain development and AR. Lover of gadgets, apps, technology and gaming.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

9 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ragesh D Antony
Ragesh D Antony
6 years ago

Thank you. You solved my problem

Ralph
Ralph
6 years ago

Thank you :) ! I have been stuck on it for a while!

Jitu
4 years ago

Great job explaining this

Ioannis
Ioannis
4 years ago

Thank you :D

Anudeep
Anudeep
4 years ago

Thank you, You solved my problem.

Carlos Casca
Carlos Casca
4 years ago

Thank you, You solved my problem.

Nidhi Singh
Nidhi Singh
3 years ago

My problem is not solved using this solution. Help!!

Joel Rives
Joel Rives
2 years ago
Reply to  Nidhi Singh

This did not solve my problem. I have the following in my Maven POM:
<!– https://mvnrepository.com/artifact/org.slf4j/slf4j-api –>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.32</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 –>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.32</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api –>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>

Joel Rives
Joel Rives
2 years ago

This did not solve my problem. I have the following in my Maven POM:
<!– https://mvnrepository.com/artifact/org.slf4j/slf4j-api –&gt;
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.32</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 –&gt;
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.32</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api –&gt;
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>

Back to top button