Chapter 4. Configuring JSON logging format
You can change the output format of the console log to JSON to make it easier to process and store the log information for later analysis.
To configure the JSON logging format, you need to add the quarkus-logging-json extension to your Quarkus project. The quarkus-logging-json extension replaces the output format configuration from the console configuration. The console configuration items such as the format string and the color settings will be ignored. Other console configuration items, including those controlling asynchronous logging and the logging level, continue to be applied.
Procedure
Add the
quarkus-logging-jsonextension to thepom.xmlfile of your application:pom.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) Set a profile-specific configuration for JSON logging in your
application.propertiesfile:src/main/resources/application.properties
%<profile>.<configuration_key>=<value>
%<profile>.<configuration_key>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following example shows how you can disable JSON logging for the development and test profiles:
src/main/resources/application.properties
%dev.quarkus.log.console.json=false %test.quarkus.log.console.json=false
%dev.quarkus.log.console.json=false %test.quarkus.log.console.json=falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.1. JSON logging configuration properties Copy linkLink copied to clipboard!
You can configure the JSON logging extension with the following configuration properties:
| Configuration property | Description | Type | Default |
|---|---|---|---|
|
| Enable the JSON console formatting extension. | boolean |
|
|
| Enable pretty printing of the JSON record. [a] | boolean |
|
|
|
The format for dates. The | string |
|
|
| Special end-of-record delimiter. By default, newline is used as delimiter. | string | |
|
|
The ID for zone. The | string |
|
|
| The output type for exception. |
|
|
|
| Enable detailed printing of the logs. The details include the source class name, source file name, source method name, and source line number. [b] | boolean |
|
[a]
Some processors and JSON parsers might fail to read pretty printed output.
[b]
Printing the details can be expensive as the values are retrieved from the caller.
| |||