933

My application is to be deployed on both tcServer and WebSphere 6.1. This application uses ehCache and so requires slf4j as a dependency. As a result I've added the slf4j-api.jar (1.6) jar to my war file bundle.

The application works fine in tcServer except for 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.

However, when I deploy in WebSphere I get a java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder.

Also accompanied by Failed to load class "org.slf4j.impl.StaticMDCBinder"

I've checked the classpaths of both application servers and there is no other slf4j jar.

Does anyone have any ideas what may be happening here?

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
DJ180
  • 18,724
  • 21
  • 66
  • 117

38 Answers38

852

I had the same issue with WebSphere 6.1. As Ceki pointed out, there were tons of jars that WebSphere was using and one of them was pointing to an older version of slf4j.

The No-Op fallback happens only with slf4j -1.6+ so anything older than that will throw an exception and halts your deployment.

There is a documentation in SLf4J site which resolves this. I followed that and added slf4j-simple-1.6.1.jar to my application along with slf4j-api-1.6.1.jar which I already had.

If you use Maven, add the following dependencies, with ${slf4j.version} being the latest version of slf4j

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>${slf4j.version}</version>
</dependency>

This solved my issue.

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
Prasanna
  • 10,956
  • 2
  • 28
  • 40
  • 5
    Yes, the error goes as also mentioned here - http://www.slf4j.org/manual.html But i get a new error now - Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory – david blaine Apr 17 '13 at 07:10
  • 2
    "As Ceki pointed out, there were tons of jars that WebSphere was using and one of them was pointing to a older version of slf4j." - So much for Maven taking care of dependencies! What a joke. – Johann Mar 21 '14 at 17:39
  • 228
    Hey you MAVEN users: http://mvnrepository.com/artifact/org.slf4j/slf4j-simple/1.6.2 – Sergio Jul 08 '14 at 16:55
  • 2
    I'm using 1.7 and has the same problem. I add slf4j-simple-1.7.jar and now the problem solved. – littletiger May 27 '15 at 22:02
  • @Sergio maven solution is not working on jenkins Linux box. But it does work on local machine , not sure what may be going wrong ? – vikramvi May 02 '16 at 15:49
  • @Sergio's maven xml should be included in the answer. Thanks! – Edenshaw Aug 10 '16 at 15:15
  • It worked for me with the version 1.7.25 when I encountered the issue in android environment. @Edenshaw It's been said in other answers. I also created one for gradle. – Vrakfall May 28 '18 at 19:43
  • Not a very good answer - why not explain the solution instead of using a link which doesn't do that great of a job explaining it –  Feb 03 '19 at 22:47
  • 1
    This doesn't work for me. The slf4j-simple jar doesn't pick up the log4j.properties. Instead, I use the implementation by adding slf4j-log4j12 and log4j jar, which works well for me. – flyrain Feb 14 '19 at 22:38
  • 8
    My comment doesn't deserve its own answer but make sure that the scope isn't just set to test. (test; don't do this) – BWC semaJ Mar 04 '19 at 05:08
  • I am using ktor-wbsockets in my android app in Kotlin and I got same error. Could you please help me how do I import slf4j to my app? – weera Jul 14 '20 at 19:36
  • 1
    slf4j-simple has slf4j-api as dependecy, so you need just that – madx Jun 02 '21 at 22:20
  • What do sbt users do? – kev Oct 06 '22 at 08:25
  • This is the only answer that worked for me. Instead of the errors, I started seeing log messages. – tarekahf Jun 23 '23 at 22:44
473

This is for those who came here from google search.

If you use maven just add the following

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

Or

   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.6.4</version>
   </dependency>
chown
  • 51,908
  • 16
  • 134
  • 170
Igor Katkov
  • 6,290
  • 1
  • 16
  • 17
  • 3
    Is there a reason for `slf4j-simple` not to be the same version as `slf4j-api`? They would probably work well together, but I think it is safer and a better practice in general to have them use the same version. Also, if you need to enable console-only logging, for instance, when running unit tests, then `slf4j-simple` seems to be enough (it was for me though). – Ivaylo Slavov May 12 '14 at 10:03
  • 35
    AFAIK you should have just 1 impl of slf4j, i.e. either slf4j-log4j12 OR slf4j-simple, not both. – Ondra Žižka Aug 01 '14 at 01:48
  • @Igor KatKov this works only on local machine but getting same error on Jenkins not sure what is going wrong. can you please clarify – vikramvi May 02 '16 at 15:26
  • slf4j-api requires configuration which is not available when you first run it (and haven't edited any configuration files). Using slf4j-simple will allow you to use basic Logger without configuring any files but WYSIWYG. You can then move back to slf4j-api once you have learned to configure the files and customize the Logger output how you like. (Still learning where there are and how to edit them myself) – chrips Apr 02 '18 at 05:01
  • Second dependency worked for me. First one created another warning *WARN No appenders could be found for logger (org.semanticweb.owlapi.utilities.Injector).* – Gireesh Sep 24 '20 at 06:33
109

Simply add this to your pom.xml:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.21</version>
</dependency>
Benny Code
  • 51,456
  • 28
  • 233
  • 198
  • 8
    The solution worked for me; It is worth pointing to the documentation (where I found the error explained): http://www.slf4j.org/codes.html#StaticLoggerBinder – Witold Kaczurba Dec 23 '16 at 07:05
  • 5
    nothing else but this worked for me while running a simple kafka producer example. thanks a bunch! – Viren Apr 20 '18 at 04:00
  • @WitoldKaczurba is right. I was having the same issue while using dependency using maven. I just googled and went to http://www.slf4j.org/codes.html#StaticLoggerBinder which states the problem and its solution. I was using slf4j-api version 1.7.25. After checking documentation on mentioned link I just used `org.slf4j slf4j-simple 1.7.25 ` and problem was resolved – Mohammad Anas Feb 05 '20 at 05:04
  • I don't understand the point of using Maven if libraries which need some logger (e.g. Handlebars which needs slf4j) don't declare it in their pom. Anyway : thank you. – Eric Duminil Apr 17 '20 at 08:53
  • 1
    In my case, this is not solution. It is only hide information, that there are incompatible versions of slf4j and log4j or another plugin. – hariprasad Apr 28 '20 at 16:20
  • 2
    Seems to be version specific. This also solved the issue for me. – Pieterjan Spoelders Apr 14 '22 at 14:30
66

Quite a few answers here recommend adding the slf4j-simple dependency to your maven pom file. You might want to check for the most current version.

At https://mvnrepository.com/artifact/org.slf4j/slf4j-simple you'll find the latest version of the SLF4J Simple Binding. Pick the one that suites you best (still 1.7.32 from 2021-07 is the stable version as of 2021-10) and include it to your pom.xml.

For your convenience some dependencies are shown here - but they might not be up-to-date when you read this!

Alpha Version of 2021-08

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>2.0.0-alpha5</version>
 </dependency>

Beta Version of Feb 2019

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.8.0-beta4</version>
</dependency>

Stable Version 2021-07

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>1.7.32</version>
</dependency>

I removed the scope test part thanks to the comment below.

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • 9
    why do you use `test`? In my experience, I at least need `runtime` scope to ensure the `slf4j-simple` is on the classpath. Curious how you got this to work with only `test` scope... – ecoe Feb 14 '18 at 00:44
  • 1
    Thank you for pointing this out. I removed the scope tag from my answer accordingly. It was a cut&paste issue - the link I am supplying provides the beta dependency this way. – Wolfgang Fahl Feb 14 '18 at 05:58
51

You need to add following jar file in your classpath: slf4j-simple-1.6.2.jar. If you don't have it, please download it. Please refer to http://www.slf4j.org/codes.html#multiple_bindings

David J.
  • 31,569
  • 22
  • 122
  • 174
Ashish
  • 14,295
  • 21
  • 82
  • 127
41

Sometime we should see the note from the warnin SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details..

This happens when no appropriate SLF4J binding could be found on the class path

You can search the reason why this warning comes.
Adding one of the jar from *slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar* to the class path should solve the problem.

compile "org.slf4j:slf4j-simple:1.6.1"

for example add the above code to your build.gradle or the corresponding code to pom.xml for maven project.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Edward
  • 1,239
  • 13
  • 20
34

I was facing same error. I have configured slf4j-api, slf4j-log4j12 and log4j, in my local development. All configuration was fine, but slf4j-log4j12 dependency which I copied from mvnrepository had test scope <scope>test</scope>. When I removed this every thing is fine.

Some times silly mistakes breaks our head ;)

thangaraj
  • 525
  • 5
  • 5
16

put file slf4j-log4j12-1.6.4.jar in the classpath will do the trick.

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
stones333
  • 8,588
  • 1
  • 25
  • 27
12

SLF4j is an abstraction for various logging frameworks. Hence apart from having slf4j you need to include any of your logging framework like log4j or logback (etc) in your classpath.
To have an idea refer the First Baby Step in http://logback.qos.ch/manual/introduction.html

Anver Sadhat
  • 3,074
  • 1
  • 25
  • 26
  • 2
    Adding logback fixed this for me. I dropped latest logback classic into pom (1.1.7) and it failed because slf4j dependency was too old (1.6.2). Downgrading logback to 1.0.0 and leaving slf4j at 1.6.x worked, as did upgrading slf4j to 1.7.20 and leaving logback at 1.1.7. – ECDragon Apr 09 '16 at 12:17
12

If you are using maven to dependency management so you can just add following dependency in pom.xml

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.6</version>
</dependency>

For non-Maven users Just download the library and put it into your project classpath.

Here you can see details: http://www.mkyong.com/wicket/java-lang-classnotfoundexception-org-slf4j-impl-staticloggerbinder/

shohan
  • 303
  • 3
  • 16
  • 1
    Also for maven users I found that I needed to add the following into pom.xml, which also brings in logback-core automatically: ch.qos.logback logback-classic 1.0.9 – Paul Aug 05 '15 at 12:07
  • 2
    `This is not an error. This message tells you that you do not have any logger implementation (such as e.g. Logback) added in classpath, and therefore NOP (No Operation) log` [Look for sarxos comment](https://github.com/sarxos/webcam-capture/issues/278) as mentioned by @Paul need to add logback-classic. Another approach of change to `slf4j-simple` from `slf4j-api` also does the work. It is illustrated [here](http://saltnlight5.blogspot.sg/2013/08/how-to-configure-slf4j-with-different.html) – Abhijeet Nov 19 '15 at 11:50
9

I got into this issue when 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.

when I was using slf4j-api-1.7.5.jar in my libs.

Inspite I tried with the whole suggested complement jars, like slf4j-log4j12-1.7.5.jar, slf4j-simple-1.7.5 the error message still persisted. The problem finally was solved when I added slf4j-jdk14-1.7.5.jar to the java libs.

Get the whole slf4j package at http://www.slf4j.org/download.html

Lucky
  • 16,787
  • 19
  • 117
  • 151
user278049
  • 113
  • 1
  • 4
9

I was facing the similar problem with Spring-boot-2 applications with Java 9 library.

Adding the following dependency in my pom.xml solved the issue for me:

<dependency>
    <groupId>com.googlecode.slf4j-maven-plugin-log</groupId>
    <artifactId>slf4j-maven-plugin-log</artifactId>
    <version>1.0.0</version>
</dependency>
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
KayV
  • 12,987
  • 11
  • 98
  • 148
7
     <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>

Put above mentioned dependency in pom.xml file

Ajay
  • 917
  • 3
  • 12
  • 26
6

Slf4j is a facade for the underlying logging frameworks like log4j, logback, java.util.logging.

To connect with underlying frameworks, slf4j uses a binding.

  • log4j - slf4j-log4j12-1.7.21.jar
  • java.util.logging - slf4j-jdk14-1.7.21.jar etc

The above error is thrown if the binding jar is missed. You can download this jar and add it to classpath.

For maven dependency,

<dependency> 
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.21</version>
</dependency>

This dependency in addition to slf4j-log4j12-1.7.21.jar,it will pull slf4j-api-1.7.21.jar as well as log4j-1.2.17.jar into your project

Reference: http://www.slf4j.org/manual.html

6

Please add the following dependencies to pom to resolve this issue.

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.25</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.25</version>
</dependency>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
gowthamjs23
  • 342
  • 5
  • 17
6

As an alternative to the jar inclusion and pure maven solutions, you can include it from maven with gradle.

Example for version 1.7.25

// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
api group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'

Put this within the dependencies of your build.gradle file.

Vrakfall
  • 966
  • 7
  • 13
5

In the Websphere case, you have an older version of slf4j-api.jar, 1.4.x. or 1.5.x lying around somewhere. The behavior you observe on tcServer, that is fail-over to NOP, occurs on slf4j versions 1.6.0 and later. Make sure that you are using slf4j-api-1.6.x.jar on all platforms and that no older version of slf4j-api is placed on the class path.

Ceki
  • 26,753
  • 7
  • 62
  • 71
  • Thanks, I've checked my WebSphere 6.1 classpath and I do not see any other version of slf4j e.g. I did a search on my WebSphere filesystem for *slf4j*jar and I only got my 1.6 version returned. Do you know if WebSphere comes packaged with slf4j? – DJ180 Sep 20 '11 at 18:26
  • Anything is possible but I'd be very surprised if WebSphere came bundled with slf4j-api. Weld bundles slf4j-api.jar. Are you using Weld? – Ceki Sep 21 '11 at 21:15
3

I am working in a project Struts2+Spring. So it need a dependency slf4j-api-1.7.5.jar.

If I run the project, I am getting error like

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

I solved my problem by adding the slf4j-log4j12-1.7.5.jar.

So add this jar in your project to solve the issue.

Lucky
  • 16,787
  • 19
  • 117
  • 151
softmage99
  • 797
  • 1
  • 8
  • 15
3

As SLF4J Manual states

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and log4j.

and

The warning will disappear as soon as you add a binding to your class path.

So you should choose which binding do you want to use.

NoOp binding (slf4j-nop)

Binding for NOP, silently discarding all logging.

Check fresh version at https://search.maven.org/search?q=g:org.slf4j%20AND%20a:slf4j-nop&core=gav

Simple binding (slf4j-simple)

outputs all events to System.err. Only messages of level INFO and higher are printed. This binding may be useful in the context of small applications.

Check fresh version at https://search.maven.org/search?q=g:org.slf4j%20AND%20a:slf4j-simple&core=gav

Bindings for the logging frameworks (java.util.logging, logback, log4j)

You need one of these bindings if you are going to write log to a file.

See description and instructions at https://www.slf4j.org/manual.html#projectDep


My opinion

I would recommend Logback because it's a successor to the log4j project.

Check latest version of the binding for it at https://search.maven.org/search?q=g:ch.qos.logback%20AND%20a:logback-classic&core=gav

You get console output out of the box but if you need to write logs into file just put FileAppender configuration to the src/main/resources/logback.xml or to the src/test/resources/logback-test.xml just like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>logs/logs.log</file>

        <encoder>
            <pattern>%date %level [%thread] %logger{10} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="debug">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>

    <logger level="DEBUG" name="com.myapp"/>
</configuration>

(See detailed description in manual: https://logback.qos.ch/manual/configuration.html)

Ilya Serbis
  • 21,149
  • 6
  • 87
  • 74
3

this can resolve using the same version. I tried this and solved it

      <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <version>1.7.5</version>
   </dependency>
Asanka Sampath
  • 545
  • 4
  • 12
2

According to SLF4J official documentation

Failed to load class org.slf4j.impl.StaticLoggerBinder

This warning message is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

Simply add this jar along with slf4j api.jar to your classpath to get things done. Best of luck

Roushan
  • 4,074
  • 3
  • 21
  • 38
2

I added this dependency to resolve this issue:

https://mvnrepository.com/artifact/org.slf4j/slf4j-simple/1.7.25
Amado Saladino
  • 2,114
  • 23
  • 25
2

Most likely your problem was because of <scope>test</scope> (in some cases also <scope>provided</scope>), as mentioned @thangaraj.

Documentation says:

This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. Test dependencies aren’t transitive and are only present for test and execution classpaths.

So, if you don't need dependecies for test purposes then you can use instead of (what you will see in mvnrepository):

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-nop</artifactId>
    <version>1.7.24</version>
    <scope>test</scope>
</dependency>

Without any scopes (by default would be compile scope when no other scope is provided):

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
<dependency>  
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-nop</artifactId>
   <version>1.7.25</version>
</dependency>

This is the same as:

 <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
 <dependency>  
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-nop</artifactId>
   <version>1.7.25</version>
   <scope>compile</scope>
 </dependency>
invzbl3
  • 5,872
  • 9
  • 36
  • 76
2

Here are my 5 cents...

I had the same issues while running tests. So I've fixed it by adding an implementation for the test runtime only. I'm using gradle for this project.

// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic

testRuntimeOnly group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

Community
  • 1
  • 1
Esteban
  • 1,496
  • 17
  • 22
2

encountered the same problem on payara 5.191

jcl-over-slf4j together with slf4j-log4j12 solved the problem

<properties>
  <slf4j.version>1.7.29</slf4j.version>
</properties>

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>${slf4j.version}</version>
  <type>jar</type>
</dependency> 

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jcl-over-slf4j</artifactId>
  <version>${slf4j.version}</version>
</dependency>        

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>${slf4j.version}</version>
</dependency>
2

As per the SLF4J Error Codes

Failed to load class org.slf4j.impl.StaticLoggerBinder This warning message is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

Note that slf4j-api versions 2.0.x and later use the ServiceLoader mechanism. Backends such as logback 1.3 and later which target slf4j-api 2.x, do not ship with org.slf4j.impl.StaticLoggerBinder. If you place a logging backend which targets slf4j-api 2.0.x, you need slf4j-api-2.x.jar on the classpath. See also relevant faq entry.

SINCE 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.

If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message. Note that embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose.

Vishal Barvaliya
  • 197
  • 1
  • 3
  • 14
2

for me the total fix was:

1

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

plus

2 create file log4j.properties

and add inside:

# Root logger option
log4j.rootLogger=INFO, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

else I got some exceptions in the console.

vlatko606
  • 909
  • 1
  • 13
  • 21
2

In my case, I replaced log4j-slf4j-impl with log4j-slf4j2-impl when doing an upgrade of the dependencies, which caused the error message. Reverting to slf4j (without the '2') solved the problem.

Tinus Tate
  • 2,237
  • 2
  • 12
  • 33
1

I solve it adding this library: slf4j-simple-1.7.25.jar You can download this in official web https://www.slf4j.org/download.html

Luis Manrique
  • 308
  • 3
  • 15
1

For me the issue was: Using Hibernate, I saw that it already used slf4j, and it was in my classpath already, so I decided to use it. The next step - adding imlementor for slf4j, so I added to maven:

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.7.25</version>
</dependency>

But it failed with error! SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”

The solution was: Hibernate's dependency of slf4j was version 1.7.26, and I added minor version dependency 1.7.25. So when I fixed this - all became OK

JeSa
  • 559
  • 4
  • 11
0

I know this post is a little old, but in case anyone else runs into this problem:

Add slf4j-jdk14-X.X.X.jar to your CLASSPATH (where X.X.X is the version number - e.g. slf4j-jdk14-1.7.5.jar).

HTH Peter

midiman
  • 11
  • 1
    Are you suggesting that users should revert to JDK1.4 logging to resolve a classpath issue? Also look at this FAQ entry: http://slf4j.org/faq.html#need_to_recompile – mwhs Nov 06 '13 at 14:49
0

I use Jena and I add the fellowing dependence to pom.xml

<dependency> 
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.0.13</version>
</dependency>

I try to add slf4j-simple but it just disappear the "SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”" error but logback-classic show more detail infomation.

The official document

Pingjiang Li
  • 727
  • 1
  • 12
  • 27
0

the solution is indicated on their official website :

Failed to load class org.slf4j.impl.StaticLoggerBinder

This warning message is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem. SINCE 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation. If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message. Note that embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose.

solution : I have added to my project using maven research on intellij and i have chosen the slf4j-jdk14.jar.

Badr Bellaj
  • 11,560
  • 2
  • 43
  • 44
0

I had similar issue and it got resolved by doing the following:

  1. File -> Project Structure...
  2. Module -> Dependencies
  3. New Library -> From Maven -> Search for: slf4j.nop
  4. Click on the latest version -> Apply
wolf23
  • 1
  • 2
0

After upgrading logback-classic to latest version: 1.4.5, I ran into this issue SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" . logback-classic:1.4.x don't have class org.slf4j.impl.StaticLoggerBinder and hence the issue.

FYI: slf4j-api 2.0.x will no longer search for StaticLoggerBinding. Refer to https://www.slf4j.org/faq.html#changesInVersion200 for more details.

raok1997
  • 369
  • 5
  • 12
0

Android dev here. For me it was upgrading to Amplify version 2.4.1 that broke the logback-android.

Uriel Frankel
  • 14,304
  • 8
  • 47
  • 69
0

I had faced same issue and after some hustle Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem

While I had to supply logback-classic.jar, still need to ensure correct version of logback-classic.jar, logback-core.jar be provided.

enter image description here

https://logback.qos.ch/dependencies.html

Chandan Gawri
  • 364
  • 1
  • 4
  • 15
-1

I did not add any dependencies, I just change the way I was consuming them.

Preview code

(Uncomment this code if you are using elastic search version < 7.0)

IndexRequest indexRequest = new IndexRequest(
  "twitter",
  "tweets",
  id // this is to make our consumer idempotent
).source(record.value(), XContentType.JSON);

Current code

IndexRequest indexRequest = new IndexRequest("tweets")
  .source(record.value(), XContentType.JSON)
  .id(id); // this is to make our consumer idempotent

I am using bulkrequest and with that I remove that error.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77