Quarkus - Configuring Logging

This guide explains logging and how to configure it.

Internally, Quarkus uses JBoss Log Manager and the JBoss Logging facade.
You can use the JBoss Logging facade inside your code as it’s already provided, or any of the supported Logging API listed in the next chapter as Quarkus will send them to JBoss Log Manager.

All the logging configuration will then be done inside your application.properties.

Supported Logging APIs

Applications and components may use any of the following APIs for logging, and the logs will be merged:

Internally Quarkus uses JBoss Logging; you can also use it inside your application so that no other dependencies should be added for your logs.

  1. import org.jboss.logging.Logger;
  2. import javax.ws.rs.GET;
  3. import javax.ws.rs.Path;
  4. import javax.ws.rs.Produces;
  5. import javax.ws.rs.core.MediaType;
  6. @Path("/hello")
  7. public class ExampleResource {
  8. private static final Logger LOG = Logger.getLogger(ExampleResource.class);
  9. @GET
  10. @Produces(MediaType.TEXT_PLAIN)
  11. public String hello() {
  12. LOG.info("Hello");
  13. return "hello";
  14. }
  15. }
If you use JBoss Logging but one of your libraries uses a different logging API, you may need to configure a Logging Adapter.

What about Apache Log4j ?

Log4j is a logging implementation: it contains a logging backend and a logging facade. Quarkus uses the JBoss Log Manager backend, so you will need to include the log4j2-jboss-logmanager library to route Log4j logs to JBoss Log Manager.

  1. <dependency>
  2. <groupId>org.jboss.logmanager</groupId>
  3. <artifactId>log4j2-jboss-logmanager</artifactId> (1)
  4. </dependency>
1This is the library needed for Log2J version 2; if you use the legacy Log4J version 1 you need to use log4j-jboss-logmanager instead.

You can then use the Log4J API inside your application.

Do not include any Log4j dependencies. The log4j2-jboss-logmanager library includes what’s needed to use Log4j as a logging facade.

Logging levels

These are the log levels used by Quarkus:

OFF

Special level to turn off logging.

FATAL

A critical service failure/complete inability to service requests of any kind.

ERROR

A significant disruption in a request or the inability to service a request.

WARN

A non-critical service error or problem that may not require immediate correction.

INFO

Service lifecycle events or important related very-low-frequency information.

DEBUG

Messages that convey extra information regarding lifecycle or non-request-bound events which may be helpful for debugging.

TRACE

Messages that convey extra per-request debugging information that may be very high frequency.

ALL

Special level for all messages including custom levels.

In addition, the following levels may be configured for applications and libraries using java.util.logging:

SEVERE

Same as ERROR.

WARNING

Same as WARN.

CONFIG

Service configuration information.

FINE

Same as DEBUG.

FINER

Same as TRACE.

FINEST

Event more debugging information than TRACE, maybe with even higher frequency.

Runtime configuration

Run time logging is configured in the application.properties file, for example, to set the default log level to INFO logging and include Hibernate DEBUG logs:

  1. quarkus.log.level=INFO
  2. quarkus.log.category."org.hibernate".level=DEBUG

All possible properties are listed in the logging configuration reference.

If you are adding these properties via command line make sure is escaped. For example -Dquarkus.log.category.\”org.hibernate\”.level=DEBUG.

Logging categories

Logging is done on a per-category basis. Each category can be independently configured. A configuration which applies to a category will also apply to all sub-categories of that category, unless there is a more specific matching sub-category configuration. For every category the same settings that are configured on ( console / file / syslog ) apply. These can also be overridden by attaching a one or more named handlers to a category. See example in Named handlers attached to a category

Property NameDefaultDescription

quarkus.log.category.”<category-name>”.level

INFO [1]

The level to use to configure the category named <category-name>. The quotes are necessary.

quarkus.log.category.”<category-name>”.use-parent-handlers

true

Specify whether or not this logger should send its output to its parent logger.

quarkus.log.category.”<category-name>”.handlers=[<handler>]

empty [2]

The names of the handlers that you want to attach to a specific category.

The quotes shown in the property name are required as categories normally contain ‘.’ which must be escaped. An example is shown in File TRACE Logging Configuration.

Root logger configuration

The root logger category is handled separately, and is configured via the following properties:

Property NameDefaultDescription

quarkus.log.level

INFO

The default minimum log level for every log category.

If no level configuration exists for a given logger category, the enclosing (parent) category is examined. If no categories are configured which enclose the category in question, then the root logger configuration is used.

Logging Format

By default, Quarkus uses a pattern-based logging formatter that generates human-readable text logs.

You can configure the format for each log handler via a dedicated property. For the console handler, the property is quarkus.log.console.format.

The logging format string supports the following symbols:

SymbolSummaryDescription

%%

%

Renders a simple % character.

%c

Category

Renders the category name.

%C

Source class

Renders the source class name.[3]

%d{xxx}

Date

Renders a date with the given date format string, which uses the syntax defined by java.text.SimpleDateFormat.

%e

Exception

Renders the thrown exception, if any.

%F

Source file

Renders the source file name.[3]

%h

Host name

Renders the system simple host name.

%H

Qualified host name

Renders the system’s fully qualified host name, which may be the same as the simple host name, depending on OS configuration.

%i

Process ID

Render the current process PID.

%l

Source location

Renders the source location information, which includes source file name, line number, class name, and method name.[3]

%L

Source line

Renders the source line number.[3]

%m

Full Message

Renders the log message plus exception (if any).

%M

Source method

Renders the source method name.[3]

%n

Newline

Renders the platform-specific line separator string.

%N

Process name

Render the name of the current process.

%p

Level

Render the log level of the message.

%r

Relative time

Render the time in milliseconds since the start of the application log.

%s

Simple message

Renders just the log message, with no exception trace.

%t

Thread name

Render the thread name.

%t{id}

Thread ID

Render the thread ID.

%z{<zone name>}

Time zone

Set the time zone of the output to <zone name>.

%X{<MDC property name>}

Mapped Diagnostics Context Value

Renders the value from Mapped Diagnostics Context

%X

Mapped Diagnostics Context Values

Renders all the values from Mapped Diagnostics Context in format {property.key=property.value}

%x

Nested Diagnostics context values

Renders all the values from Nested Diagnostics Context in format {value1.value2}

Alternative Console Logging Formats

It is possible to change the output format of the console log. This can be useful in environments where the output of the Quarkus application is captured by a service which can, for example, process and store the log information for later analysis.

JSON Logging Format

In order to configure the JSON logging format, the quarkus-logging-json extension may be employed. Add this extension to your application POM as the following snippet illustrates.

Modifications to POM file to add the JSON logging extension

  1. <dependencies>
  2. <!-- ... your other dependencies are here ... -->
  3. <dependency>
  4. <groupId>io.quarkus</groupId>
  5. <artifactId>quarkus-logging-json</artifactId>
  6. </dependency>
  7. </dependencies>

The presence of this extension will, by default, replace the output format configuration from the console configuration. This means that the format string and the color settings (if any) will be ignored. The other console configuration items (including those controlling asynchronous logging and the log level) will continue to be applied.

For some, it will make sense to use logging that is humanly readable (unstructured) in dev mode and JSON logging (structured) in production mode. This can be achieved using different profiles, as shown in the following configuration.

Disable JSON logging in application.properties for dev and test mode

  1. %dev.quarkus.log.console.json=false
  2. %test.quarkus.log.console.json=false
Configuration

The JSON logging extension can be configured in various ways. The following properties are supported:

Enabling pretty printing might cause certain processors and JSON parsers to fail.
Printing the details can be expensive as the values are retrieved from the caller. The details include the source class name, source file name, source method name and source line number.

Log Handlers

A log handler is a logging component responsible for the emission of log events to a recipient. Quarkus comes with three different log handlers: console, file and syslog.

Console log handler

The console log handler is enabled by default. It outputs all log events to the console of your application (typically to the system’s stdout).

For details of its configuration options, see the Console Logging configuration reference.

File log handler

The file log handler is disabled by default. It outputs all log events to a file on the application’s host. It supports log file rotation.

For details of its configuration options, see the File Logging configuration reference.

Syslog log handler

Syslog is a protocol for sending log messages on Unix-like systems using a protocol defined by RFC 5424.

The syslog handler sends all log events to a syslog server (by default, the syslog server that is local to the application). It is disabled by default.

For details of its configuration options, see the Syslog Logging configuration reference.

Examples

Console DEBUG Logging except for Quarkus logs (INFO), No color, Shortened Time, Shortened Category Prefixes

  1. quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
  2. quarkus.log.console.level=DEBUG
  3. quarkus.log.console.color=false
  4. quarkus.log.category."io.quarkus".level=INFO
If you are adding these properties via command line make sure is escaped. For example -Dquarkus.log.category.\”io.quarkus\”.level=DEBUG.

File TRACE Logging Configuration

  1. quarkus.log.file.enable=true
  2. # Send output to a trace.log file under the /tmp directory
  3. quarkus.log.file.path=/tmp/trace.log
  4. quarkus.log.file.level=TRACE
  5. quarkus.log.file.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
  6. # Set 2 categories (io.quarkus.smallrye.jwt, io.undertow.request.security) to TRACE level
  7. quarkus.log.category."io.quarkus.smallrye.jwt".level=TRACE
  8. quarkus.log.category."io.undertow.request.security".level=TRACE
As we don’t change the root logger, console log will only contain INFO or higher order logs.

Named handlers attached to a category

  1. # Send output to the console
  2. quarkus.log.file.path=/tmp/trace.log
  3. quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
  4. # Configure a named handler that logs to console
  5. quarkus.log.handler.console."STRUCTURED_LOGGING".format=%e%n
  6. # Configure a named handler that logs to file
  7. quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".enable=true
  8. quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".format=%e%n
  9. # Configure the category and link the two named handlers to it
  10. quarkus.log.category."io.quarkus.category".level=INFO
  11. quarkus.log.category."io.quarkus.category".handlers=STRUCTURED_LOGGING,STRUCTURED_LOGGING_FILE

Centralized Log Management

If you want to send your logs to a centralized tool like Graylog, Logstash or Fluentd, you can follow the Centralized log management guide.

How to Configure Logging for @QuarkusTest

If you want to configure logging for your @QuarkusTest, don’t forget to set up the maven-surefire-plugin accordingly. In particular, you need to set the appropriate LogManager using the java.util.logging.manager system property.

Example Configuration

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <artifactId>maven-surefire-plugin</artifactId>
  5. <version>${surefire-plugin.version}</version>
  6. <configuration>
  7. <systemPropertyVariables>
  8. <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> (1)
  9. <quarkus.log.level>DEBUG</quarkus.log.level> (2)
  10. <maven.home>${maven.home}</maven.home>
  11. </systemPropertyVariables>
  12. </configuration>
  13. </plugin>
  14. </plugins>
  15. </build>
1Make sure the org.jboss.logmanager.LogManager is used.
2Enable debug logging for all logging categories.

If you are using Gradle, add this to your build.gradle:

  1. test {
  2. systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
  3. }

See also: Running @QuarkusTest from an IDE

Logging Adapters

Quarkus relies on the JBoss Logging library for all the logging requirements.

If you are using libraries that have dependencies on other logging libraries such as Apache Commons Logging, Log4j or Slf4j, you need to exclude them from the dependencies and use one of the adapters provided by JBoss Logging.

This is especially important when building native executables as you could encounter issues similar to the following when compiling the native executable:

  1. Caused by java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl

This is due to the logging implementation not being included in the native executable. Using the JBoss Logging adapters will solve this problem.

These adapters are available for most of the common Open Source logging components, such as Apache Commons Logging:

  1. <dependency>
  2. <groupId>org.jboss.logging</groupId>
  3. <artifactId>commons-logging-jboss-logging</artifactId>
  4. </dependency>

JDK Logging:

  1. <dependency>
  2. <groupId>org.jboss.logging</groupId>
  3. <artifactId>jboss-logging-jdk</artifactId>
  4. </dependency>

Log4j:

  1. <dependency>
  2. <groupId>org.jboss.logmanager</groupId>
  3. <artifactId>log4j-jboss-logmanager</artifactId>
  4. </dependency>

Log4j2:

  1. <dependency>
  2. <groupId>org.jboss.logmanager</groupId>
  3. <artifactId>log4j2-jboss-logmanager</artifactId>
  4. </dependency>

And Slf4j:

  1. <dependency>
  2. <groupId>org.jboss.slf4j</groupId>
  3. <artifactId>slf4j-jboss-logging</artifactId>
  4. </dependency>
This is not needed for libraries that are dependencies of a Quarkus extension as the extension will take care of this for you.

Logging configuration reference

About the MemorySize format

A size configuration option recognises string in this format (shown as a regular expression): [0-9]+[KkMmGgTtPpEeZzYy]?. If no suffix is given, assume bytes.


1. Some extensions may define customized default log levels for certain categories, in order to reduce log noise by default. Setting the log level in configuration will override any extension-defined log levels.

2. By default the configured category gets the same handlers attached as the one on the root logger.

3. Format sequences which examine caller information may affect performance