Friday, 6 December 2024

How to configure Traffic Parrot log level at runtime in Docker

We got a question from one of our customers about how to configure the log level at runtime when using Traffic Parrot in Docker.
How to pass environment variables to Docker
The Dockerfile CMD command can be modified to accept environment variables as follows:
ENV GUI_HTTP_PORT=8080
ENV VS_HTTP_PORT=8081
CMD exec ./start-foreground.sh \
    trafficparrot.gui.http.port=$GUI_HTTP_PORT \
    trafficparrot.virtualservice.http.port=$VS_HTTP_PORT
How to set the logging level dynamically with Docker environment variables
First the Dockerfile can be configured with an environment variable:
ENV LOG_LEVEL=ERROR
This can be then be configured for use:
  • trafficparrotserver.log4j.properties can be configured with:
    log4j.rootLogger=${LOG_LEVEL},file,stdout
    And the Dockerfile with:
    CMD exec ./start-foreground.sh -DLOG_LEVEL=$LOG_LEVEL
  • trafficparrotserver.log4j2.xml can be configured with:
    <Root level="${env:LOG_LEVEL}">
  • trafficparrotserver.logback.xml can be configured with:
    <root level="${LOG_LEVEL}">

No comments:

Post a Comment