Systems and devices Author · iulian@iptest.ro ·
Editorial date · 2026-03-25
- Identify the log source first. System services may write to journald and applications may write files under /var/log. This example uses /var/log/app/app.log.
sudo journalctl --disk-usage- Add a rule under /etc/logrotate.d/ for the application file. Choose daily rotation, 14 archives, compression, missingok and notifempty. Check ownership, permissions and the application's guidance for reopening its log file.
sudo logrotate --debug /etc/logrotate.conf- Check whether a timer or cron runs logrotate. After the first rotation, confirm that the app writes to the new file and the archive is readable.
sudo systemctl status logrotate.timer- Copy archives you need to private storage with restricted access and encryption. Pick a retention period that meets your needs and test restoring a file.
- During an incident, preserve originals and exact timestamps before rotation. Avoid logging passwords, tokens and authentication headers.