Logging
Overview
Log files is a very important aspect of system observability, much like monitoring.
RabbitMQ starts logging early on node start. Many important pieces of information about node's state and configuration will be logged during or after node boot.
Developers and operators should inspect logs when troubleshooting an issue or assessing the state of the system.
RabbitMQ supports a number of features when it comes to logging.
This guide covers topics such as:
- What will and will not be logged by RabbitMQ nodes
- Supported log outputs: file and standard streams (console)
- Log file location
- Supported log levels
- How to activate debug logging
- How to tail logs of a running node without having access to the log file
- Watching internal events
- Connection lifecycle events logged
- Logging in JSON
- Log categories
- Advanced log formatting
- How to inspect service logs on systemd-based Linux systems
- Log rotation
- Logging to Syslog
- Logging to a system topic exchange,
amq.rabbitmq.log
and more.
What Will and Will Not Be Logged?
RabbitMQ nodes many different kinds of events, in fact, too many to name. However, there are several categories of events that are not logged by design. In most cases, these events are related to individual messages, whose high rates: tens or hundreds of thousands per seconds, or even millions with streams and superstreams:
- Message routing
- Message delivery to consumers
- Message acknowledgements by consumers
- Unroutable messages, both returned and dropped
- Consumer registration and cancelation
A significant majority of errors related to these events, such as double acknowledgements of a delivery, will be logged.
In order to reason about message routing, ingress (publishing) and egress (delivery to consumers) rates, consumer events, and unroutable messages, use metrics, watch internal events, adopt relevant client library features, and take and inspect a traffic capture.
Log Outputs
RabbitMQ nodes can log to multiple outputs. Logging to a file is one of the most common options for RabbitMQ installations.
Logging to standard output and error streams is another popular option. Syslog is a yet another one supported out of the box.
Different outputs can have different log levels. For example, the console output can log all messages including debug information while the file output can only log error and higher severity messages.
Default Log Output and Behavior
Nodes log to a file by default, if no outputs are explicitly configured. If some are configured, they will be used.
If logging to a file plus another output is necessary, a file output must be explicitly listed next to the other desired log outputs, for example, the standard stream one.
Log File Location
There are two ways to configure log file location. One is the configuration file. This option is recommended.
The other is the RABBITMQ_LOGS
environment variable. It can be useful in development environments.
RABBITMQ_LOGS
cannot be combined with the configuration file settings. When RABBITMQ_LOGS
is set, the logging-related settings from rabbitmq.conf
will be effectively ignored.
See the File and Directory Location guide to find default log file location for various platforms.
Log file location can be found in the RabbitMQ management UI on the node page
as well as using rabbitmq-diagnostics
:
- bash
- PowerShell
- cmd
rabbitmq-diagnostics -q log_location
rabbitmq-diagnostics.bat -q log_location
rabbitmq-diagnostics.bat -q log_location
The RABBITMQ_LOGS
variable value can be either a file path or a hyphen (-
).
Setting the value to a hyphen like so
# Instructs the node to log to standard streams.
# IMPORTANT: the environment variable takes precedence over the configuration file.
# When it is set, all logging-related rabbitmq.conf settings will be
# effectively ignored.
RABBITMQ_LOGS=-
the node will send all log messages to standard I/O streams, namely to standard output.
The environment variable takes precedence over the configuration file. When it is set,
all logging-related rabbitmq.conf
settings will be effectively ignored.
The recommended way of overriding log file location is via rabbitmq.conf
.
How Logging is Configured
Several sections below cover various configuration settings related to logging.
They all use rabbitmq.conf
, the modern configuration format.
See the Configuration guide for a general overview of how to configure RabbitMQ.
Logging to a File
Logging to a file is one of the most common options for RabbitMQ installations. In modern releases, RabbitMQ nodes only log to a file if explicitly configured to do so using the configuration keys listed below:
log.file
: log file path orfalse
to deactivate the file output. Default value is taken from theRABBITMQ_LOGS
environment variable or configuration filelog.file.level
: log level for the file output. Default level isinfo
log.file.formatter
: controls log entry format, text lines or JSONlog.file.rotation.date
,log.file.rotation.size
,log.file.rotation.count
for log file rotation settingslog.file.formatter.time_format
: controls timestamp formatting
The following example overrides log file name:
log.file = rabbit.log
The following example overrides log file location:
log.file = /opt/custom/var/log/rabbit.log
The following example instructs RabbitMQ to log to a file at the debug
level:
log.file.level = debug
For a list of supported log levels, see Log Levels.
Logging to a file can be deactivated with
log.file = false
Logging in JSON format to a file:
log.file.formatter = json
By default, RabbitMQ will use RFC 3339 timestamp format. It is possible to switch to a UNIX epoch-based format:
log.file = true
log.file.level = info
# use microseconds since UNIX epoch for timestamp format
log.file.formatter.time_format = epoch_usecs
The rest of this guide describes more options, including more advanced ones.
Log Rotation
When logging to a file, the recommended rotation option is logrotate
RabbitMQ nodes always append to the log files, so a complete log history is preserved.
Log file rotation is not performed by default. Debian and RPM packages will set up
log rotation via logrotate
after package installation.
log.file.rotation.date
, log.file.rotation.size
, log.file.rotation.count
settings control log file rotation
for the file output.
Rotation Using Logrotate
On Linux, BSD and other UNIX-like systems, logrotate is a widely used log file rotation tool. It is very mature and supports a lot of options.
RabbitMQ Debian and RPM packages will set up logrotate
to run weekly on files
located in default /var/log/rabbitmq
directory. Rotation configuration can be found in /etc/logrotate.d/rabbitmq-server
.
Built-in Periodic Rotation
log.file.rotation.date
cannot be combined with log.file.rotation.size
, the two
options are mutually exclusive
Use log.file.rotation.date
to set up minimalistic periodic rotation:
# rotate every night at midnight
log.file.rotation.date = $D0
# keep up to 5 archived log files in addition to the current one
log.file.rotation.count = 5
# archived log files will be compressed
log.file.rotation.compress = true
# rotate every day at 23:00 (11:00 p.m.)
log.file.rotation.date = $D23
Built-in File Size-based Rotation
log.file.rotation.size
cannot be combined with log.file.rotation.date
, the two
options are mutually exclusive
log.file.rotation.size
controls rotation based on the current log file size:
# rotate when the file reaches 10 MiB
log.file.rotation.size = 10485760
# keep up to 5 archived log files in addition to the current one
log.file.rotation.count = 5
# archived log files will be compressed
log.file.rotation.compress = true
Logging to Console (Standard Output)
Logging to standard streams (console) is another popular option for RabbitMQ installations, in particular when RabbitMQ nodes are deployed in containers. RabbitMQ nodes only log to standard streams if explicitly configured to do so.
Here are the main settings that control console (standard output) logging:
log.console
(boolean): set totrue
to activate console output. Default is `falselog.console.level
: log level for the console output. Default level isinfo
log.console.formatter
: controls log entry format, text lines or JSONlog.console.formatter.time_format
: controls timestamp formatting
To activate console logging, use the following config snippet:
log.console = true
The following example deactivates console logging
log.console = false
The following example instructs RabbitMQ to use the debug
logging level when logging to console:
log.console.level = debug
For a list of supported log levels, see Log Levels.
Logging to console in JSON format:
log.console.formatter = json
When console output is activated, the file output will also be activated by default.
To deactivate the file output, set log.file
to false
:
log.console = true
log.console.level = info
log.file = false
By default, RabbitMQ will use RFC 3339 timestamp format. It is possible to switch to a UNIX epoch-based format:
log.console = true
log.console.level = info
log.file = false
# use microseconds since UNIX epoch for timestamp format
log.console.formatter.time_format = epoch_usecs
Please note that RABBITMQ_LOGS=-
will deactivate the file output
even if log.file
is configured.
Logging to Syslog
RabbitMQ logs can be forwarded to a Syslog server via TCP or UDP. UDP is used by default and requires Syslog service configuration. TLS is also supported.
Syslog output has to be explicitly configured:
log.syslog = true