1

I am getting error: SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.

The error is happening when using log4j-over-slf4j, slf4j-reload4j, or slf4j-log4j12. But everything works just fine with slf4j-simple. How can I use log4j over slf4j?

Here is my App:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class App {

    private final static Logger log = LoggerFactory.getLogger(App.class);
    public static void main(String[] args) {
        log.error("Success");
    }
}

And below is build.gradle.

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {

    compile 'org.slf4j:slf4j-api:2.0.7'
    compile 'org.slf4j:log4j-over-slf4j:2.0.7'
//    compile 'org.slf4j:slf4j-reload4j:2.0.7'
//    compile 'org.slf4j:slf4j-log4j12:2.0.7'
//    compile 'org.slf4j:slf4j-simple:2.0.7'
}

AlexA
  • 11
  • 2
  • Does this answer your question? [java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class pat](https://stackoverflow.com/questions/18320146/java-lang-illegalstateexception-detected-both-log4j-over-slf4j-jar-and-slf4j-lo) – Piotr P. Karwasz Mar 30 '23 at 14:33
  • Your symptoms are different, but the reason is the same: you can not both have a Log4j 1.2 to SLF4J bridge and SLF4J to Log4j 1.2 bridge. BTW: Log4j 1.2 reached end-of-life 8 years ago. – Piotr P. Karwasz Mar 30 '23 at 14:35
  • Thanks, @PiotrP.Karwasz! Could you suggest me how exactly should I change the build.gradle? – AlexA Mar 30 '23 at 16:30
  • It all depends what do you want to achieve. Normally you code against a logging API (latest generation: SLF4J and Log4j2 API) and you need a logging backend (latest generation: Logback and Log4j2 Core). Dont' use Log4j 1.2 in your code (it's not an API with selectable backends) and don't use it as backend. – Piotr P. Karwasz Mar 30 '23 at 18:42

0 Answers0