When managing server logs, two prominent tools emerge: cronolog and logrotate. While both serve log rotation purposes, their approaches differ fundamentally.
Cronolog operates as a pipe, processing log data in real-time. It's particularly useful when integrated directly with applications:
# Apache configuration using cronolog
CustomLog "|/usr/bin/cronolog /var/log/apache2/access.%Y-%m-%d.log" combined
Key characteristics:
- Creates new log files based on time patterns
- No need for process restart
- Lightweight with minimal configuration
Logrotate follows a more traditional approach with periodic execution:
# Sample logrotate configuration for Nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 cat /var/run/nginx.pid
endscript
}
Notable features:
- Comprehensive configuration options
- Built-in compression support
- Flexible rotation triggers (size/time)
In high-traffic environments, cronolog typically shows better performance as it eliminates the need for periodic rotation processing. However, logrotate provides more comprehensive file management capabilities including compression and archival.
For web servers like Apache or Nginx:
- Cronolog excels when you need precise time-based segmentation
- Logrotate works better when you need complex retention policies
For application logs:
- Cronolog is ideal when the application can pipe output directly
- Logrotate is preferable when dealing with existing log files
For maximum flexibility, some administrators combine both tools:
# Using cronolog for initial segmentation
CustomLog "|/usr/bin/cronolog /var/log/apache2/access.%Y-%m-%d.log" combined
# Then applying logrotate for compression and retention
/var/log/apache2/access.*.log {
daily
rotate 30
compress
}
With cronolog:
- Ensure proper permissions on the pipe
- Verify the cronolog process is running
With logrotate:
- Check configuration file syntax
- Verify post-rotation scripts execute correctly
When managing server logs in Linux environments, two prominent tools emerge for log rotation: cronolog and logrotate. Both serve the critical purpose of preventing log files from consuming excessive disk space while maintaining organized historical data.
Cronolog operates as a simple pipe-based filter that writes logs to time-stamped files. It's often used with web servers like Apache:
CustomLog "|/usr/sbin/cronolog /var/log/httpd/access.%Y-%m-%d.log" combined
Logrotate is a more comprehensive solution that handles rotation, compression, and deletion through configuration files:
/var/log/nginx/*.log { daily missingok rotate 14 compress delaycompress notifempty create 0640 www-data adm sharedscripts postrotate /usr/sbin/nginx -s reload endscript }
Cronolog excels in high-volume logging scenarios where you need continuous rotation without service interruptions. It creates new log files based on time patterns without requiring process restarts.
Logrotate provides more features but typically requires a daily cron job and may need service restarts for proper log file handling.
For complex log rotation needs, logrotate offers more flexibility:
/var/log/myapp/*.log { hourly size 100M rotate 5 compress dateext dateformat -%Y%m%d%H extension .log sharedscripts postrotate kill -HUP cat /var/run/myapp.pid endscript }
Cronolog configuration is simpler but less feature-rich:
ErrorLog "|/usr/bin/cronolog /var/log/apache/error.%Y-%m-%d-%H.log"
Choose Cronolog when:
- You need continuous rotation without gaps
- Your application can pipe logs directly
- You prefer time-based rather than size-based rotation
Choose Logrotate when:
- You need compression and archival features
- Your system has multiple log files to manage
- You require complex rotation policies (size + time)
- You need post-rotation script execution
Both tools work well with containerized environments. For Docker, consider these approaches:
# Logrotate in containers volumes: - ./logrotate.conf:/etc/logrotate.d/app # Cronolog with stdout command: ["/usr/sbin/apache2", "-D", "FOREGROUND", "-D", "CRONOLOG"]