Set up logging for WebSphere Liberty container images
We can observe the logs created by WebSphere Liberty when it is running in a container. If we emit the logs in JSON, we can then use them with a logging stack of the choice.
Configure our WebSphere Liberty container image to emit JSON formatted logs to the console (or standard-out) with your selection of WebSphere Liberty logging events by providing the following environment variables to our WebSphere Liberty Dockerfile.
-
//This example illustrates the use of all available logging sources.
ENV WLP_LOGGING_CONSOLE_FORMAT=JSON
ENV WLP_LOGGING_CONSOLE_LOGLEVEL=info
ENV WLP_LOGGING_CONSOLE_SOURCE=message,trace,accessLog,ffdc,audit
Alternately, these environment variables can be set when we run the container. To do so, use the -e option with the run command to pass in an environment variable value.
-
docker run \
-d \
-p 80:9080 \
-p 443:9443 \
-e WLP_LOGGING_CONSOLE_FORMAT=JSON \
-e WLP_LOGGING_CONSOLE_LOGLEVEL=info \
-e WLP_LOGGING_CONSOLE_SOURCE=message,trace,accessLog,ffdc,audit websphere-liberty:latest
See Logging and Trace in the WebSphere Liberty documentation.