Bejenariu Ionut
Bejenariu Ionut

Reputation: 1

Logging not working with sl4j annotation even if it is in my dependency tree

I am working on a small project with spring boot and the logging seems to not work. I receive this:

2025-03-02 13:44:41 [JDALogger] [WARN] Using fallback logger due to missing SLF4J implementation.
2025-03-02 13:44:41 [JDALogger] [WARN] Please setup a logging framework to use JDA.
2025-03-02 13:44:41 [JDALogger] [WARN] You can use our logging setup guide https://jda.wiki/setup/logging/
2025-03-02 13:44:41 [JDALogger] [WARN] To disable the fallback logger, add the slf4j-nop dependency or use JDALogger.setFallbackLoggerEnabled(false)
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.

This is my pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.30</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.dv8tion</groupId>
            <artifactId>JDA</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.11.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>5.14.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-parent</artifactId>
            <version>1.16.2</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>2.43.0</version>

                <configuration>
                    <java>
                        <palantirJavaFormat/>
                    </java>
                </configuration>

                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>1.16.2</version>
            </plugin>
        </plugins>
    </build>
</project>

I am using the sl4j annotation. I saw de library sl4j-api in my dependency tree. I tried adding manually also the sl4j manually and it still seems to work that way. Any idea why it is not working without that approach? Sl4j-api doesn't contain the implementation for logging?

Upvotes: 0

Views: 36

Answers (1)

chamDev
chamDev

Reputation: 21

SLF4J alone is not a logging implementation. You need to add a logging implementation, such as slf4j-nop.jar, slf4j-simple.jar, slf4j-reload4j.jar, slf4j-jdk14.jar, or logback-classic.jar, to the classpath.

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

Upvotes: 2

Related Questions