Jul 222023
 

Quarkus framework has its own logging system, based on JBoss logging. There is a more or less simple system with configuration via properties (or yaml). In simple cases, features from default Quarkus logging are enough, but for complex cases, like MDC, log separation, etc standard Quarkus logging capability is insufficient.

Another thing that brings some problems is tests, especially in gradle, because there is no way to specify the logging level by package name for tests (at least it doesn’t work for me up to Quarkus v. 3.2.0).

So at least one solution – use another logging framework you like. It can be Logback, Log4J or even JUL. By the way, there is already developed option for using logback.xml as a log configuration source, but only in a static way – transcode logback.xml into standard Quarkus logging settings at the build stage.

In this case for using another logging framework we need to replace the existing one.

  • Remove unnecessary packages from the build: build.gradle
configurations.all {
 exclude group: 'org.jboss.logging', module: 'jboss-logmanager-embedded'
 exclude group: 'org.jboss.logging', module: 'commons-logging-jboss-logging'
 exclude group: 'org.jboss.slf4j', module: 'slf4j-jboss-logmanager'
 exclude group: 'org.slf4j', module: 'slf4j-jdk14'
}
  • Add required dependencies: build.gradle
dependencies {
...
 implementation "org.slf4j:slf4j-api:${slf4jVersion}"
 implementation "ch.qos.logback:logback-core:${logbackVersion}"
 implementation "ch.qos.logback:logback-classic:${logbackVersion}"
...
}
  • Use the required logging provider on the application start command
java -Dorg.jboss.logging.provider=slf4j -jar quarkus-runner.jar

Also sometimes we need to tune logging in gradle test task: build.gradle

test {
  systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
  systemProperty "org.jboss.logging.provider", "slf4j"
// one file for multimodule project
  systemProperty 'logback.configurationFile', "${rootDir}/src/test/resources/logback-test.xml"
}

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)