best way to rotate rabbitmq log files
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
RabbitMQ, a popular open-source message broker, uses logs to provide insights into its operations, performance issues, and debugging information. Efficient log management, including rotation, is essential to prevent logs from using excessive disk space and to maintain a clean logging environment. This article outlines the best strategies for rotating RabbitMQ log files, particularly focusing on filesystem-based log rotations and RabbitMQ's internal log rotation mechanisms.
Understanding RabbitMQ Log Files
RabbitMQ logs different types of information:
- Erlang crash dumps: Occur when the Erlang VM crashes.
- SASL logs: Contains information about RabbitMQ's authentication and authorization.
- Regular logs: General logs that include client connections, disconnections, and administrative actions.
These log files are by default located in the RabbitMQ server node's base directory (e.g., /var/log/rabbitmq on Linux systems).
Log Rotation Strategies
1. Using RabbitMQ's Built-in Log Rotation
RabbitMQ supports basic log rotation natively. Configuration can be set in RabbitMQ's advanced.config file or through environment variables. Here's an example to configure log rotation in the advanced.config:
This configuration snippet does two things:
- It sets log level details for various modules.
- It enables log rotation when logs reach 10MB or daily.
2. External Log Rotation Tools
System administrators often use external tools like logrotate on Linux for more sophisticated log rotation mechanisms. Here is an example logrotate configuration for RabbitMQ logs:
This configuration enables daily rotations, keeps ten backup files, compresses rotated files, and changes file permissions appropriately. The postrotate script trigger RabbitMQ to close the current log file and open a new one, ensuring that no log entries are lost during the rotation.
Best Practices for Log Rotation
- Size-based rotation: Apart from time-based (e.g., daily), consider rotating logs once they reach a certain size to prevent any single log file from consuming too much disk space.
- Compress old log files: Compressing older files saves significant disk space.
- Monitor log directory size: Set up monitoring on the log directory itself to alert if total disk usage goes beyond a certain threshold.
Summary Table
| Method | Configuration Location | Rotation Trigger | Post-rotation Action |
| Built-in RabbitMQ | advanced.config | File size or date | Automatically handled |
| External tool (logrotate) | /etc/logrotate.d/ | Timed or size-based | Requires manual script setup |
Conclusion
Effective log management is crucial for maintaining the health and performance of RabbitMQ servers. While RabbitMQ provides some internal support for log rotation, using external tools like logrotate can provide more flexibility and robustness. By implementing these strategies, you can ensure that log files are rotated efficiently, maintaining system performance and reliability.
Related reading
- Bidirectional messaging system using kafka
- Book for Django + Celery + RabbitMQ?
- bootstrap-server vs zookeeper params in consumer console
- Bootstrap server vs zookeeper in kafka?
- best way to seed new machine with k8s/eks info
- Best way to synchronize MySQL bases on different servers
- Bucket records based on time(kafka-hdfs-connector)
- Build a multi node Kafka cluster on docker swarm

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.