1

I'm trying to add Logback on a Vertx project, but it seems SLF4J can't see logback even if itself come from a logback dependency. I used maven dependency logback-classic, which transitively imports slf4j-api and logback-core.

When I run a simple main class with random log I have the following 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.

My pom.xml:

<?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>com.example</groupId>
  <artifactId>vertx-stock-broker</artifactId>
  <version>1.0.0-SNAPSHOT</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
    <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
    <exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>

    <vertx.version>4.5.11</vertx.version>
    <logback-classic.version>1.5.12</logback-classic.version>
    <junit-jupiter.version>5.9.1</junit-jupiter.version>

    <main.verticle>com.example.vertx_stock_broker.MainVerticle</main.verticle>
    <launcher.class>io.vertx.core.Launcher</launcher.class>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-stack-depchain</artifactId>
        <version>${vertx.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-web</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback-classic.version}</version>
    </dependency>

    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
          <release>17</release>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <version>${maven-shade-plugin.version}</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer
                  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>${launcher.class}</Main-Class>
                    <Main-Verticle>${main.verticle}</Main-Verticle>
                  </manifestEntries>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              </transformers>
              <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar
              </outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>${exec-maven-plugin.version}</version>
        <configuration>
          <mainClass>${launcher.class}</mainClass>
          <arguments>
            <argument>run</argument>
            <argument>${main.verticle}</argument>
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>


</project>

The running class:

package com.example.vertx_stock_broker;

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

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

  public static void main(String[] args) {
    LOG.debug("debug");
    LOG.info("info");
    LOG.error("error");
  }
}

I run it with the IntelliJ run tool which silently run (I have shorten paths with '...'):

openjdk-22.0.2\bin\java.exe "-javaagent:...\IntelliJ IDEA 2024.2.3\lib\idea_rt.jar=64366:...\IntelliJ IDEA 2024.2.3\bin" 
-Dfile.encoding=UTF-8 
-Dsun.stdout.encoding=UTF-8 
-Dsun.stderr.encoding=UTF-8 
-classpath ...\vertx-stock-broker\target\classes;
    ....m2\repository\io\vertx\vertx-web\4.5.11\vertx-web-4.5.11.jar;
    ....m2\repository\io\vertx\vertx-web-common\4.5.11\vertx-web-common-4.5.11.jar;
    ....m2\repository\io\vertx\vertx-auth-common\4.5.11\vertx-auth-common-4.5.11.jar;
    ....m2\repository\io\vertx\vertx-bridge-common\4.5.11\vertx-bridge-common-4.5.11.jar;
    ....m2\repository\io\vertx\vertx-core\4.5.11\vertx-core-4.5.11.jar;
    ....m2\repository\io\netty\netty-common\4.1.115.Final\netty-common-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-buffer\4.1.115.Final\netty-buffer-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-transport\4.1.115.Final\netty-transport-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-handler\4.1.115.Final\netty-handler-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-transport-native-unix-common\4.1.115.Final\netty-transport-native-unix-common-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-codec\4.1.115.Final\netty-codec-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-handler-proxy\4.1.115.Final\netty-handler-proxy-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-codec-socks\4.1.115.Final\netty-codec-socks-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-codec-http\4.1.115.Final\netty-codec-http-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-codec-http2\4.1.115.Final\netty-codec-http2-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-resolver\4.1.115.Final\netty-resolver-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-resolver-dns\4.1.115.Final\netty-resolver-dns-4.1.115.Final.jar;
    ....m2\repository\io\netty\netty-codec-dns\4.1.115.Final\netty-codec-dns-4.1.115.Final.jar;
    ....m2\repository\com\fasterxml\jackson\core\jackson-core\2.16.1\jackson-core-2.16.1.jar;
    ....m2\repository\ch\qos\logback\logback-core\1.5.12\logback-core-1.5.12.jar;
    ....m2\repository\org\slf4j\slf4j-api\2.0.7\slf4j-api-2.0.7.jar com.example.vertx_stock_broker.MainVerticle

My logback.xml file:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

I didn't find any dependencies conflict or duplication. OpenJdk22 is used.

I expect to get logback logs at runtime

Edit:

Thanks to @Ceki answer, it appear that the problem was with IntelliJ, the logback-classic jar was not provided in the classpath generated run command, after an IntelliJ cache clean and a restart the problem was solved. Now logback-classic is provided in classpath and it work as expected.

2
  • My logback.xml file... And is that in ...\vertx-stock-broker\target\classes? Commented Dec 2, 2024 at 15:46
  • @g00se Yes it is Commented Dec 2, 2024 at 16:00

1 Answer 1

0

FYI, logback-classic.jar is the slf4j provider not logback-core.jar. The former seems to be missing from the class path of InterlliJ Idea that you provided.

Sign up to request clarification or add additional context in comments.

4 Comments

Ho yes I mistaken, I will edit my question. Add indeed we can't found it in the given classpath, I will search why
mvn dependency:build-classpath -Dmdep.outputFile=cp.txt should put the correct classpath in that file for you
@Ceki you gave me the way, it was more like an IntelliJ bug, I cleaned the cache and restarted it, and then it worked. The classpath now contain logback-classic too
No problem. Ceki, you are the author of Logback and I claim my $5 ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.