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.2binjava.exe "-javaagent:...IntelliJ IDEA 2024.2.3libidea_rt.jar=64366:...IntelliJ IDEA 2024.2.3bin"
-Dfile.encoding=UTF-8
-Dsun.stdout.encoding=UTF-8
-Dsun.stderr.encoding=UTF-8
-classpath ...vertx-stock-brokertargetclasses;
....m2repositoryiovertxvertx-web4.5.11vertx-web-4.5.11.jar;
....m2repositoryiovertxvertx-web-common4.5.11vertx-web-common-4.5.11.jar;
....m2repositoryiovertxvertx-auth-common4.5.11vertx-auth-common-4.5.11.jar;
....m2repositoryiovertxvertx-bridge-common4.5.11vertx-bridge-common-4.5.11.jar;
....m2repositoryiovertxvertx-core4.5.11vertx-core-4.5.11.jar;
....m2repositoryionettynetty-common4.1.115.Finalnetty-common-4.1.115.Final.jar;
....m2repositoryionettynetty-buffer4.1.115.Finalnetty-buffer-4.1.115.Final.jar;
....m2repositoryionettynetty-transport4.1.115.Finalnetty-transport-4.1.115.Final.jar;
....m2repositoryionettynetty-handler4.1.115.Finalnetty-handler-4.1.115.Final.jar;
....m2repositoryionettynetty-transport-native-unix-common4.1.115.Finalnetty-transport-native-unix-common-4.1.115.Final.jar;
....m2repositoryionettynetty-codec4.1.115.Finalnetty-codec-4.1.115.Final.jar;
....m2repositoryionettynetty-handler-proxy4.1.115.Finalnetty-handler-proxy-4.1.115.Final.jar;
....m2repositoryionettynetty-codec-socks4.1.115.Finalnetty-codec-socks-4.1.115.Final.jar;
....m2repositoryionettynetty-codec-http4.1.115.Finalnetty-codec-http-4.1.115.Final.jar;
....m2repositoryionettynetty-codec-http24.1.115.Finalnetty-codec-http2-4.1.115.Final.jar;
....m2repositoryionettynetty-resolver4.1.115.Finalnetty-resolver-4.1.115.Final.jar;
....m2repositoryionettynetty-resolver-dns4.1.115.Finalnetty-resolver-dns-4.1.115.Final.jar;
....m2repositoryionettynetty-codec-dns4.1.115.Finalnetty-codec-dns-4.1.115.Final.jar;
....m2repositorycomfasterxmljacksoncorejackson-core2.16.1jackson-core-2.16.1.jar;
....m2repositorychqoslogbacklogback-core1.5.12logback-core-1.5.12.jar;
....m2repositoryorgslf4jslf4j-api2.0.7slf4j-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.
Mickael Alvarez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
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.
4