1

After moving from JDK8 to JDK11 I get "SLF4J: No SLF4J providers were found" and not logging. Using Maven and IntelliJ.

Output:

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.

In JDK8 I had these in the pom.xml and it all worked very well.

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

I looking around and followed a tip and added slf4j18-impl but I still have the same problem. This is is how it looks in the pom.xml right now:

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.19.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.19.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.19.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j18-impl</artifactId>
      <version>2.18.0</version>
   </dependency>

And this kind of code did work in JDK8 but not in JDK11


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

public class TestOutput {
  private static final Logger LOG = LoggerFactory.getLogger(TestOutput.class);

  public static void tryToLog() {
      LOG.info("Hello world!");
  }
}

user1857773
  • 71
  • 2
  • 7
  • Why do you have both `log4j-slf4j-impl` and `log4j-slf4j18-impl`? My guess is that these have a conflict the `slf4j-api` version they depend on. – Rob Spoor Dec 09 '22 at 13:55
  • 2
    SLF4J 1.8.x and 2.0.x are incompatible. The abandoned module `log4j-slf4j18-impl` is a binding for SLF4J 1.8.x, the binding for SLF4J 2.0.x is called `log4j-slf4j2-impl`. BTW: if you have `log4j-api` as _compile_ dependency, why don't you use Log4j2 API directly in your code? – Piotr P. Karwasz Dec 09 '22 at 13:59
  • Does this answer your question? [Exception with Slf4j with log4j2 implementation](https://stackoverflow.com/questions/70660379/exception-with-slf4j-with-log4j2-implementation) – Piotr P. Karwasz Dec 09 '22 at 14:02
  • 1
    @Ceki, of course I was talking about incompatibility of SPIs. An SLF4J 1.8.x binding such as `log4j-slf4j18-impl` will not work with SLF4J 2.0.x (and no one expects that). If someone understood my comment as stating that the APIs are incompatible, I apologize. Semantically there is no API breakage between SLF4J 1.x and 2.x. – Piotr P. Karwasz Dec 10 '22 at 14:07

1 Answers1

1

Adding only one dependency for slf4j:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.6.6</version>
</dependency>
Jai Prakash
  • 162
  • 1
  • 10