1. Why use logrotate
- Avoid huge logs
- Keep history for debugging
- Reduce full-disk risk
2. Global config
Check the main file (typically):
/etc/logrotate.conf
Also check included directories (if present).
3. Example config for a custom log
/var/log/myapp/*.log {
weekly
rotate 8
compress
missingok
notifempty
create 0640 root root
sharedscripts
postrotate
/etc/rc.d/rc.myapp restart >/dev/null 2>&1 || true
endscript
}
4. Meaning of key options
weekly: weekly rotationrotate 8: keep 8 archivescompress: compress rotated logsmissingok: do not fail if the file is missingnotifempty: do not rotate empty files
5. Manual test
logrotate -d /etc/logrotate.conf # debug, no changes
logrotate -f /etc/logrotate.conf # force rotation
Use
-f with care on production systems: it may rotate many files at once.6. Checks
ls -lh /var/log/myapp
tail -n 50 /var/log/messages
7. Common errors
- Wrong permissions on logs or directories
- Wrong path in the rule
- Failing
postrotatecommand - Service not reopening the log file
Quick checklist
[ ] logrotate rule created
[ ] Test with -d completed
[ ] Test with -f completed (if appropriate)
[ ] create permissions verified
[ ] postrotate checked