Search code examples
logbackquarkus

How to get JSON logging with Quarkus and Logback?


I would like to use logback for JSON logging together with Quarkus (1.2.1.Final).

I have put the following logback.xml into the resources folder:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <withJansi>false</withJansi>
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <provider class="net.logstash.logback.composite.loggingevent.ArgumentsJsonProvider"/>
            <fieldNames>
                <message>logmessage</message>
            </fieldNames>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>

</configuration>

I'm using this maven dependency:

<dependency>
  <groupId>net.logstash.logback</groupId>
  <artifactId>logstash-logback-encoder</artifactId>
  <version>4.11</version>
</dependency>

However I'm getting no JSON logging.

The logger I am obtaining via (using Kotlin)

import org.slf4j.LoggerFactory
private val LOGGER = LoggerFactory.getLogger(javaClass)

Solution

  • Fixed it by changing dependencies to

    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>6.3</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.3</version>
    </dependency>
    

    Docu from https://github.com/logstash/logstash-logback-encoder#including-it-in-your-project