I’m trying to log in JSON format using --log-console-output=json, which works very well. Thanks for including this functionality.
{ "timestamp": "2022-02-25T10:31:32.452+01:00", "sequence": 8442, "loggerClassName": "org.jboss.logging.Logger", "loggerName": "io.quarkus", "level": "INFO", "message": "Keycloak 18.0.0-SNAPSHOT on JVM (powered by Quarkus 2.7.2.Final) started in 3.253s. Listening on: http://0.0.0.0:8080", "threadName": "main", "threadId": 1, "mdc": {}, "ndc": "", "hostName": "host-name", "processName": "QuarkusEntryPoint", "processId": 36946 }
However, I’m facing two main issues with the above log:
- Creating New Fields outside of MDC block:
- I tried using the property
quarkus.log.json.fields.mdc.flat-fields=trueto flatten MDC fields, but it isn’t working and the other ways I tried are static (additional-field) and cannot be changed for every request (eg ipAddress)
- Formatting Stacktraces:
I attempted to create new fields using the following configuration:
'KC_LOG_CONSOLE_FORMAT': '{"EventTime":"%d{yyyy-MM-dd HH:mm:ss,SSS}","level":"%-5p","logger":"%c","thread":"%t","requestId":"%X{requestId}","event":"%s","stackTrace": "%s%E"}%n'
- This works well for creating new fields, but exceptions come with newline characters. I couldn’t find a way to format exceptions in a single line or JSON as
--log-console-output=jsondoes.
I am aware of the custom log handler option, but it requires CDI, and I’m not sure if it can be integrated well with Keycloak: GitHub - quarkiverse/quarkus-logging-json: Quarkus logging extension outputting the logging in json..
Could anyone provide input on how I could deal with these issues, specifically:
- Flattening MDC fields or
- Formatting stacktraces to appear in a single line or in JSON format?
Thank you!