The JSON log format in Open Liberty makes log analysis more effective. In this video, see how to use JSON logging with Open Liberty, which will prepare you for using log analysis tools and is a good fit for Docker containers.
Sample Open Liberty configuration
This configuration, in bootstraps.properties, directs messages, trace, FFDC, access log, and audit events to stdout (console). Trace, access logs, and audit can be high volume, so you need to consider that when deciding what to include in the sources directed to the console:
com.ibm.ws.logging.console.format=json com.ibm.ws.logging.console.log.level=info com.ibm.ws.logging.console.source=message,trace,accessLog,ffdc,audit
If you don’t need your messages.log file, clear the source list and set message format to JSON:
Avoid having a separate trace.log file by directing trace to stdout (console). You can omit this property if you want your trace logs to be directed to your trace file:
Sample command to enable JSON logging in your Docker image using environment variables:
docker run \ -e "WLP_LOGGING_CONSOLE_SOURCE=message,trace,accessLog,ffdc,audit" \ -e "WLP_LOGGING_CONSOLE_FORMAT=json" \ -e "WLP_LOGGING_CONSOLE_LOGLEVEL=info" \ -e "WLP_LOGGING_MESSAGE_FORMAT=json" \ -e "WLP_LOGGING_MESSAGE_SOURCE=" \ -e WLP_LOGGING_JSON_FIELD_MAPPINGS=loglevel:level,message:log open-liberty
WLP_LOGGING_JSON_FIELD_MAPPINGS environment variable allows you to change default JSON field names.
JQ is a (non-IBM) command-line JSON processor you can use to format the output into a more human readable format. JQ command examples:
Just include the message:
alias prettylog="jq '.message' -r"
Include the datetime, log level, message:
alias prettylog="jq '.ibm_datetime + \" \" + .loglevel + \"\\t\" + \" \" + .message' -r"
Pipe docker container logs into JQ query:
Link to logging configurations: