google-cloud-platformrabbitmqansi-colors

Turn off ANSI colors in console logs


How can I turn off ANSI colors from RabbitMQ console logs?

I have a RabbitMQ instance that logs to console in order to catch log messages elsewhere (on GCP logs for example). The problem is that, all log messages are prefixed with ANSI color codes, which cause the logs to be interpreted as INFO always.

For example, on errors, RabbitMQ logs with [38;5;160m prefix, which corresponds for the red color. See screenshots.

Here is my rabbitmq.conf

log.console = true
log.console.level = error
log.file = false

enter image description here


Solution

  • In most production environments, you would want to analyse your logs. This becomes easier when the logs are formatted in a structured way. In RabbitMQ it is possible to format logs in JSON, which will also solve your ANSI colouring problem:

    log.file.formatter = json
    log.console.formatter = json
    log.syslog.formatter = json