This guide explains logging and how to configure it.
Runtime configuration
Run time logging is configured in the application.properties
file,
for example to set everything to INFO
logging except Hibernate:
quarkus.log.level=INFO
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 Name | Default | Description |
---|---|---|
|
|
The level to use to configure the category named |
|
|
Specify whether or not this logger should send its output to its parent logger. |
|
|
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. |
Format String
The logging format string supports the following symbols:
Symbol | Summary | Description |
---|---|---|
|
|
Renders a simple |
|
Category |
Renders the category name. |
|
Source class |
Renders the source class name.[3] |
|
Date |
Renders a date with the given date format string, which uses the syntax defined by |
|
Exception |
Renders the thrown exception, if any. |
|
Source file |
Renders the source file name.[3] |
|
Host name |
Renders the system simple host name. |
|
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. |
|
Process ID |
Render the current process PID. |
|
Source location |
Renders the source location information, which includes source file name, line number, class name, and method name.[3] |
|
Source line |
Renders the source line number.[3] |
|
Full Message |
Renders the log message plus exception (if any). |
|
Source method |
Renders the source method name.[3] |
|
Newline |
Renders the platform-specific line separator string. |
|
Process name |
Render the name of the current process. |
|
Level |
Render the log level of the message. |
|
Relative time |
Render the time in milliseconds since the start of the application log. |
|
Simple message |
Renders just the log message, with no exception trace. |
|
Thread name |
Render the thread name. |
|
Thread ID |
Render the thread ID. |
|
Time zone |
Set the time zone of the output to |
|
Mapped Diagnostics Context Value |
Renders the value from Mapped Diagnostics Context |
|
Mapped Diagnostics Context Values |
Renders all the values from Mapped Diagnostics Context in format {property.key=property.value} |
|
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
In order to configure JSON logging, the quarkus-logging-json
extension may be employed. Add this extension to your
application POM as the following snippet illustrates.
<dependencies>
<!-- ... your other dependencies are here ... -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-json</artifactId>
</dependency>
</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.
%dev.quarkus.log.console.json=false
%test.quarkus.log.console.json=false
Configuration
The JSON logging extension can be configured in various ways. The following properties are supported:
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting. |
boolean |
|
Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read pretty printed output. |
boolean |
|
The date format to use. The special string "default" indicates that the default format should be used. |
string |
|
The special end-of-record delimiter to be used. By default, no delimiter is used. |
string |
|
The zone ID to use. The special string "default" indicates that the default zone should be used. |
string |
|
The exception output type to specify. |
|
|
Enable printing of more details in the log. 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. |
boolean |
|
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. |
Examples
quarkus.log.console.enable=true
quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
quarkus.log.console.level=DEBUG
quarkus.log.console.color=false
quarkus.log.category."io.quarkus".level=DEBUG
If you are adding these properties via command line make sure " is escaped.
For example -Dquarkus.log.category.\"io.quarkus\".level=DEBUG .
|
quarkus.log.file.enable=true
# Send output to a trace.log file under the /tmp directory
quarkus.log.file.path=/tmp/trace.log
quarkus.log.file.level=TRACE
quarkus.log.file.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
# Set 2 categories (io.quarkus.smallrye.jwt, io.undertow.request.security) to TRACE level
quarkus.log.category."io.quarkus.smallrye.jwt".level=TRACE
quarkus.log.category."io.undertow.request.security".level=TRACE
# Send output to the console
quarkus.log.file.path=/tmp/trace.log
quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
# Configure a named handler that logs to console
quarkus.log.handler.console."STRUCTURED_LOGGING".format=%e%n
# Configure a named handler that logs to file
quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".enable=true
quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".format=%e%n
# Configure the category and link the two named handlers to it
quarkus.log.category."io.quarkus.category".level=INFO
quarkus.log.category."io.quarkus.category".handlers=STRUCTURED_LOGGING,STRUCTURED_LOGGING_FILE
Supported Logging APIs
Applications and components may use any of the following APIs for logging, and the logs will be merged:
-
JDK
java.util.logging
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.
Logging configuration reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
The log level of the root category, which is used as the default log level for all categories. |
|
|
The default minimum log level |
|
|
Type |
Default |
|
The log level level for this category |
InheritableLevel |
|
The names of the handlers to link to this category. |
list of string |
|
Specify whether or not this logger should send its output to its parent Logger |
boolean |
|
Type |
Default |
|
If console logging should be enabled |
boolean |
|
The log format. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension). |
string |
|
The console log level. |
|
|
If the console logging should be in color. If undefined quarkus takes best guess based on operating system and environment. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension). |
boolean |
|
Specify how much the colors should be darkened. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension). |
int |
|
Indicates whether to log asynchronously |
boolean |
|
The queue length to use before flushing writing |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full |
|
|
Type |
Default |
|
If file logging should be enabled |
boolean |
|
The log format |
string |
|
The level of logs to be written into the file. |
|
|
The name of the file in which logs will be written. |
|
|
Indicates whether to log asynchronously |
boolean |
|
The queue length to use before flushing writing |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full |
|
|
The maximum file size of the log file after which a rotation is executed. |
||
The maximum number of backups to keep. |
int |
|
File handler rotation file suffix. Example fileSuffix: .yyyy-MM-dd |
string |
|
Indicates whether to rotate log files on server initialization. |
boolean |
|
Type |
Default |
|
If syslog logging should be enabled |
boolean |
|
The IP address and port of the syslog server |
host:port |
|
The app name used when formatting the message in RFC5424 format |
string |
|
The name of the host the messages are being sent from |
string |
|
Sets the facility used when calculating the priority of the message as defined by RFC-5424 and RFC-3164 |
|
|
Set the |
|
|
Sets the protocol used to connect to the syslog server |
|
|
Set to |
boolean |
|
Set to |
boolean |
|
Enables or disables blocking when attempting to reconnect a |
boolean |
|
The log message format |
string |
|
The log level specifying, which message levels will be logged by syslog logger |
|
|
Indicates whether to log asynchronously |
boolean |
|
The queue length to use before flushing writing |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full |
|
|
Type |
Default |
|
If console logging should be enabled |
boolean |
|
The log format. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension). |
string |
|
The console log level. |
|
|
If the console logging should be in color. If undefined quarkus takes best guess based on operating system and environment. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension). |
boolean |
|
Specify how much the colors should be darkened. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension). |
int |
|
Indicates whether to log asynchronously |
boolean |
|
The queue length to use before flushing writing |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full |
|
|
Type |
Default |
|
If file logging should be enabled |
boolean |
|
The log format |
string |
|
The level of logs to be written into the file. |
|
|
The name of the file in which logs will be written. |
|
|
Indicates whether to log asynchronously |
boolean |
|
The queue length to use before flushing writing |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full |
|
|
The maximum file size of the log file after which a rotation is executed. |
||
The maximum number of backups to keep. |
int |
|
File handler rotation file suffix. Example fileSuffix: .yyyy-MM-dd |
string |
|
Indicates whether to rotate log files on server initialization. |
boolean |
|
Type |
Default |
|
If syslog logging should be enabled |
boolean |
|
The IP address and port of the syslog server |
host:port |
|
The app name used when formatting the message in RFC5424 format |
string |
|
The name of the host the messages are being sent from |
string |
|
Sets the facility used when calculating the priority of the message as defined by RFC-5424 and RFC-3164 |
|
|
Set the |
|
|
Sets the protocol used to connect to the syslog server |
|
|
Set to |
boolean |
|
Set to |
boolean |
|
Enables or disables blocking when attempting to reconnect a |
boolean |
|
The log message format |
string |
|
The log level specifying, which message levels will be logged by syslog logger |
|
|
Indicates whether to log asynchronously |
boolean |
|
The queue length to use before flushing writing |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full |
|
|
Type |
Default |
|
The message starts to match |
list of string |
|
About the MemorySize format
A size configuration option recognises string in this format (shown as a regular expression): |