skip to Main Content

I have an application that has the following error message:

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.

This message occurs after I attempt to run any script for the application. I have found that, as it says, it does not create logs, so I have come up empty handed when something fails.

I am running this in Amazon Linux 2 which is closest to CentOS and Redhat.

I have found the following resources:
This issue is addressed here: http://www.slf4j.org/codes.html#StaticLoggerBinder
I can get the jar I need from here: https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.6.2/slf4j-simple-1.6.2.jar
After taking this jar and dropping it into my application’s /lib, nothing changes.

Other articles describe adding this file to the class path. In Linux, I get this:

# java -classpath /opt/opendj/lib/slf4j-simple-1.6.2.jar org.slf4j.impl.StaticLoggerBinder
Error: Could not find or load main class org.slf4j.impl.StaticLoggerBinder
# java -jar /opt/opendj/lib/slf4j-simple-1.6.2.jar org.slf4j.impl.StaticLoggerBinder
no main manifest attribute, in /opt/opendj/lib/slf4j-simple-1.6.2.jar

Am I trying to add it to the class path right?

If needed, you can reproduce this issue by doing the following:
Steps to reproduce the behavior:
Install a fresh version of OpenDJ onto CentOS or Amazon Linux2 EC2 Instance. Install java 1.8.0
specifically java-1.8.0-openjdk
Install the server in any configuration, then run a status script.

Expected behavior
Logs should generate and no warning message can be presented.

4

Answers


  1. Firstly, you should take a look here : https://www.slf4j.org/codes.html

    Also,you can try adding these SLF4J maven dependencies into your pom and let me know if this works:

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.13.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.13.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.13.3</version>
    </dependency>
    

    Note: Consider that the maven dependencies versions are being updated, then maybe you prefer use the lates version of the dependencies(for example for log4j-api is 2.17.0)

    On the other hand, this post could help you as well:
    https://mkyong.com/java/log4j2-failed-to-load-class-org-slf4j-impl-staticloggerbinder/

    Login or Signup to reply.
  2. In my case I was getting this error while using MavenCli lib. I had missed to add maven-compat lib in pom.xml. Below is full sample code I had used.

    Sample code :

    MavenCli mavenCli=new MavenCli();
    mavenCli.doMain(new String[]{"clean","install"}, path_of_project_dir, System.out, System.out);
    

    Dependency required :

    <dependency>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-embedder</artifactId>
                <version>3.6.3</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.30</version>
            </dependency>
            <dependency>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-compat</artifactId>
                <version>3.6.3</version>
            </dependency>
    
    Login or Signup to reply.
  3. In my case, I was using the logback in a spring-boot app and faced this issue. It was related to incompatible versions of slf4j and logback which were coming from third party libraries. I excluded all of them and used these:

        <!-- logging dependencies-->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
    

    ${logback.version} and ${slf4j.version} are coming from spring-boot-dependencies-2.X.X.pom file.

    Login or Signup to reply.
  4. I hope it will help 🙂

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>2.0.6</version>
    </dependency>
    
    
    <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.4.5</version>
    </dependency>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search