Configuring Logging
1. Setting Log Level
| Property | Values | Description |
|---|---|---|
| log.level | debug, info, warn, error |
Global log level for RabbitMQ node |
| log.level.file | debug, info, warn, error |
Log level for file output |
| log.level.console | debug, info, warn, error |
Log level for console output |
2. Configuring Log File
| Property | Values | Description |
|---|---|---|
| log.file.path | /var/log/rabbitmq/rabbit.log |
Path to the log file |
| log.file.level | info |
Log level for file output (debug, info, warning, error) |
| log.file.rotation.count | 5 |
Number of rotated log files to keep |
| log.file.rotation.size | 10MB |
Maximum size of log file before rotation |
Example: Log File Configuration
log.file.path: /var/log/rabbitmq/rabbit.log
log.file.level: info
log.file.rotation.count: 5
log.file.rotation.size: 10MB
3. Using JSON Logging
| Configuration Option | Value | Description |
|---|---|---|
| log_json | true |
Enables JSON logging format |
| log_json_file | /var/log/rabbitmq/rabbit.log.json |
Path to the JSON log file |
Example: Enabling JSON Logging
[{rabbit, [{log_json, true}, {log_json_file, "/var/log/rabbitmq/rabbit.log.json"}]}].
Note: JSON logs are useful for centralized logging systems and monitoring tools that parse structured data.
4. Filtering Log Categories
| Category | Description | Default Level | Notes |
|---|---|---|---|
| amqp | AMQP protocol handling | INFO | Logs AMQP frames and connection events |
| auth | Authentication and authorization | INFO | Logs login attempts, user permissions |
| connection | Connection management | INFO | Tracks connection open/close events |
| channel | Channel operations | INFO | Logs channel creation and closure |
| queue | Queue operations | INFO | Logs queue declarations, bindings |
| exchange | Exchange operations | INFO | Logs exchange declarations and bindings |
| consumer | Consumer handling | INFO | Logs consumer registration and delivery |
| policy | Policy application | INFO | Logs policy matching and application |
| mnesia | Mnesia database operations | INFO | Logs internal state changes |
| disk | Disk I/O operations | INFO | Logs disk usage and file access |
| memory | Memory usage tracking | INFO | Logs memory allocation and limits |
| flow | Flow control operations | INFO | Logs flow control state changes |
| heartbeat | Heartbeat handling | INFO | Logs heartbeat timeouts and intervals |
| federation | Federation plugin operations | INFO | Logs federation link status and errors |
| shovel | Shovel plugin operations | INFO | Logs shovel configuration and status |
| management | Management plugin operations | INFO | Logs API calls and dashboard access |
| rabbitmq_prometheus | Prometheus metrics logging | INFO | Logs metric collection and export |
| rabbitmq_tracing | Tracing plugin operations | INFO | Logs tracing configuration and events |
| rabbitmq_consistent_hash | Consistent hash exchange plugin | INFO | Logs hash calculation and routing |
| rabbitmq_stream | Stream plugin operations | INFO | Logs stream creation and consumption |
Example: Configuring Log Levels in rabbitmq.conf
# Set log level for specific categories
log_levels.amqp = debug
log_levels.auth = warning
log_levels.connection = info
# Enable debug logging for specific components
log_levels.rabbitmq_tracing = debug
Note: Log levels can be set to
debug, info, warning, error, or none. Setting a category to none disables all logging for that category.
Warning: Enabling debug logging for all categories can significantly impact performance and disk space usage. It is recommended to use specific category filtering rather than setting all categories to debug.
5. Enabling Connection Logging
| Configuration Option | Values | Description |
|---|---|---|
| log.connection | true | false |
Enables or disables connection-level logging. Default is false. |
| log.connection.level | info | debug | warn | error |
Sets the logging level for connection events. Default is info. |
Note: Connection logging can significantly increase log volume in high-traffic environments.
6. Enabling Channel Logging
| Configuration Option | Values | Description |
|---|---|---|
| log.console | true / false |
Enable or disable console logging for channels |
| log.file | path/to/logfile.log |
Path to the log file for channel events |
| log.level | debug, info, warn, error |
Minimum level of messages to log |
Example: Enabling Channel Logging in RabbitMQ Configuration
logging:
console: true
file: /var/log/rabbitmq/channel.log
level: debug
Note: Channel logging can significantly impact performance in high-throughput environments. Consider enabling it only for debugging or monitoring specific channels.
7. Logging AMQP Commands
| Command | Description | Log Level | Notes |
|---|---|---|---|
| basic.publish | Publishes a message to an exchange | INFO | Logged when a message is successfully published |
| basic.deliver | Delivers a message to a consumer | INFO | Logged when a message is delivered to a consumer |
| basic.ack | Acks a delivered message | DEBUG | Logged when a message is acknowledged by the consumer |
| basic.nack | Nacks a delivered message | DEBUG | Logged when a message is negatively acknowledged by the consumer |
| basic.reject | Rejects a delivered message | DEBUG | Logged when a message is rejected by the consumer |
| confirm.select | Enables publisher confirms | INFO | Logged when publisher confirms are enabled |
| confirm.select | Confirms a published message | INFO | Logged when a published message is confirmed |
Example: Enabling AMQP Command Logging
# Enable AMQP command logging in RabbitMQ config
echo 'log.console = true' >> /etc/rabbitmq/rabbitmq.conf
echo 'log.console.level = debug' >> /etc/rabbitmq/rabbitmq.conf
echo 'log.file = /var/log/rabbitmq/rabbit.log' >> /etc/rabbitmq/rabbitmq.conf
echo 'log.file.level = info' >> /etc/rabbitmq/rabbitmq.conf
Note: AMQP command logging can significantly increase log volume and should be used carefully in production environments.
8. Using Syslog
| Configuration Option | Values | Description |
|---|---|---|
| vm_memory_high_watermark | 0.4 |
Percentage of total system memory that triggers memory pressure warnings |
| vm_memory_high_watermark_persistent | 0.4 |
Same as above but for persistent messages |
| disk_free_limit | 50MB |
Minimum free disk space before triggering warnings |
Example: Syslog Configuration in rabbitmq.conf
# Enable logging to syslog
log.console = off
log.syslog = on
# Set log level for syslog
log.syslog.level = info
# Define the facility and priority
log.syslog.facility = local0
log.syslog.priority = notice
Note: Ensure that your system's syslog daemon is configured to handle messages from RabbitMQ. The
local0 facility is commonly used for application-specific logs.
Warning: Misconfiguring syslog can lead to loss of critical error messages. Always verify that logs are being written correctly to the specified facility.
9. Rotating Log Files
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| log_rotate_interval | Interval after which log files are rotated | 1d |
Can be specified in days, hours, minutes, or seconds (e.g., 1h, 30m) |
| log_rotate_size | Maximum size of log file before rotation | 10MB |
When log file exceeds this size, it is rotated |
| log_rotate_count | Number of rotated log files to keep | 5 |
Older logs are deleted once this limit is reached |
Example: Configuring Log Rotation in rabbitmq.conf
# Rotate logs every day
log_rotate_interval = 1d
# Keep up to 5 rotated log files
log_rotate_count = 5
# Rotate when log file reaches 10MB
log_rotate_size = 10MB
Note: Log rotation is managed by the
rabbitmqctl utility and requires appropriate permissions to configure.
10. Parsing Log Patterns
| Log Level | Description | Typical Use Case | Example Pattern |
|---|---|---|---|
| trace | Most verbose level; includes all internal operations and debugging details. | Debugging complex issues or performance bottlenecks | [TRACE] [connection-12345] Channel opened |
| debug | Provides detailed information for developers to understand system behavior. | Development and troubleshooting | [DEBUG] [channel-67890] Message published to queue 'myqueue' |
| info | General operational messages indicating normal flow of events. | Monitoring and general system status | [INFO] [node-abcde] Node started successfully |
| warning | Indicates potential issues that do not stop operation but require attention. | System health monitoring | [WARNING] [queue-xyz] Queue 'test' has high message rate |
| error | Indicates errors that prevent a specific operation from completing. | Error tracking and alerting | [ERROR] [broker-12345] Failed to connect to broker |
| critical | Severe errors that may cause system instability or crash. | Critical incident response | [CRITICAL] [node-abcde] Memory allocation failed |
Example: Log Pattern Matching in Configuration
log:
level: debug
file:
path: "/var/log/rabbitmq/rabbit.log"
max_size: 10MB
max_files: 5
pattern:
format: "%d{yyyy-MM-dd HH:mm:ss} [%p] [%t] %m%n"
timestamp: "yyyy-MM-dd HH:mm:ss"
Note: The log pattern format can be customized using standard logging libraries like Logback (Java) or Python's logging module.
Key Points for Log Parsing
- Log levels help filter and prioritize messages based on severity.
- Custom log patterns enable structured logging for easier parsing and analysis.
- Timestamp formats should be consistent across logs to support automated parsing tools.
11. Integrating with Log Aggregators
Example: Configuring RabbitMQ to Send Logs to a Centralized Service
# Enable logging to a remote syslog server
rabbitmqctl set_vm_memory_high_watermark 0.4
rabbitmqctl set_log_level info
# Configure logging to a file for external parsing
echo 'log.dir = /var/log/rabbitmq' >> /etc/rabbitmq/rabbitmq.conf
echo 'log.file = rabbitmq.log' >> /etc/rabbitmq/rabbitmq.conf
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| log.dir | Directory where log files are stored | /var/log/rabbitmq |
Must be writable by RabbitMQ user |
| log.file | Name of the main log file | rabbitmq.log |
Can be overridden to support log rotation |
| log.syslog | Enable logging to syslog | false |
Set to true to send logs to system log |
| log.syslog_facility | Syslog facility to use | local0 |
Valid values: auth, local0-local7 |
Comparison: Log Aggregator Integration Options
- Syslog Integration: Sends logs to system log daemon (e.g., rsyslog), which can forward to centralized services like ELK stack or Splunk
- File-based Logging: Writes logs to disk, suitable for ingestion by tools like Fluentd or Logstash
- External Logging Frameworks: Use libraries like Logback or Log4j for more advanced formatting and routing
Note: Ensure that the log directory and file permissions are correctly set to allow RabbitMQ to write logs without errors.
12. Troubleshooting via Logs
| Log Level | Description | Use Case |
|---|---|---|
| debug | Most verbose level, includes detailed internal operations and state changes. | Development and deep diagnostics |
| info | General operational messages, including startup and shutdown events. | Production monitoring and general tracking |
| warning | Non-fatal issues that may require attention but don't stop operations. | Identifying potential problems before they escalate |
| error | Fatal errors that prevent normal operation or cause data loss. | Immediate incident response and root cause analysis |
Example: Setting Log Level in rabbitmq.conf
# Set the log level to debug for troubleshooting
log.level = debug
# Enable detailed logging for specific modules
log.module.amqp = debug
log.module.mnesia = info
Note: Log levels can be adjusted dynamically without restarting the broker, but changes may not take effect immediately depending on the logging backend.