13

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.

Andreas
  • 154,647
  • 11
  • 152
  • 247
Dean013
  • 323
  • 1
  • 3
  • 10
  • Why are you adding tthe jar to opendj? Is that the application that is getting the error? – rgoers May 18 '20 at 02:14
  • Yes, that is the application that is having this issue. Unlike other threads that have this issue, I am getting this issue outside of a development platform (Eclipse/maven) and do not know how to solve it. – Dean013 May 18 '20 at 12:47

4 Answers4

22

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/

mononoke83
  • 342
  • 2
  • 16
  • 1
    This helped me to solve the error. Their docs suggest this http://www.slf4j.org/codes.html#noProviders – vitaliis Jul 12 '21 at 03:02
  • Use the latest version of the dependencies after searching them at https://mvnrepository.com/ – nkr Dec 23 '21 at 11:02
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>
1

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>
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 10 '23 at 09:00
0

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.

Payam Soudachi
  • 301
  • 3
  • 5