qos-ch / slf4j

Simple Logging Facade for Java
http://www.slf4j.org
MIT License
2.34k stars 990 forks source link

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" #413

Closed ravitejamargam closed 7 months ago

ravitejamargam commented 7 months ago

I was using log4j version 2.23.1 which comes with slf4j-api version 2.0.9. Below are the dependencies: <log4j2.version>2.23.1</log4j2.version>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>${log4j2.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j2.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j2-impl</artifactId>
    <version>${log4j2.version}</version>
</dependency>

And I was using maven-assembly-plugin to build a single jar with all dependencies

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.7.1</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>assemble-all</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Included the following imports:

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

Using slf4j logger

Logger log = LoggerFactory.getLogger(Main.class);

When I run the standalone main application (fat jar including all the dependencies), I see the below log in the console

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 run same standalone main application (without fat jar) and added the above log4j and slf4j dependencies to classpath, I don't see any issue