0

I am getting below error, unable to get log statement. I haved added log config as well as in application.properties.

logging.level.com.google=TRACE
logging.level.com.example.com=TRACE

Error Log:

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.

Dependency:

implementation(libs.slf4j.api)
implementation(libs.slf4j.simple)

Code:

import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Test {

  @Test
    public void testSearh() throws Exception {
        log.trace("Test...........");
}
}
selvi
  • 1,271
  • 2
  • 21
  • 41
  • Check that you've actually added `slf4j-simple` as you are hinting at in the comment before the code block. That library provides an implementation, which is what the error message tells you is missing. – Jorn Jun 09 '23 at 11:55
  • Does this answer your question? [SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"](https://stackoverflow.com/questions/7421612/slf4j-failed-to-load-class-org-slf4j-impl-staticloggerbinder) – Brian Tompsett - 汤莱恩 Jun 12 '23 at 18:04

1 Answers1

0

So SLF4J by itself is just an API. You need to provide an implementation on the classpath.

The quickest/easiest is the following:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>2.0.7</version>
</dependency>

but something like LogBack would be better suited for production.

EDIT

You've since edited your post to show you're including the dependency. If you are still getting that error, it means it's still not finding the implementation at runtime, which likely indicates a build setup problem. Can you post your entire gradle configuration and build log?

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84