Troubleshoot Linux Logs That Won't Rotate
Before you begin
- Applies to:Linux hosts with systemd, logrotate, and an application that writes to a file.
- Where to start:Use a shell on the host that writes and rotates the log. If rotation is scheduled by systemd, use its timer and service checks.
- What you need:Have the full log path, rotation configuration and schedule, and service owner's details. Replace the example /var/log/myapp/app.log with the actual path.
Guide tools
Troubleshooting Steps
Separate a rotation problem from a logging problem
Start hereConfirm the application writes directly to a file. Journal-only logging is managed by journald. For file logging, record the current and rotated paths, inode numbers, file sizes, and last write times.
sudo ls -li -- /var/log/myappsudo stat -- /var/log/myapp/app.logVerify when logrotate actually runs
Check the timer and service logs. A timer being active only means it is scheduled. Confirm the service actually ran and inspect its exit status. If these units are absent, inspect the host’s approved cron or alternate schedule rather than adding a duplicate.
systemctl list-timers --all logrotate.timersystemctl status logrotate.service --no-pagersudo journalctl -u logrotate.service --since '7 days ago' --no-pagerPreview the effective configuration
Use the same main configuration that the scheduler uses to include global defaults and drop-ins. Debug mode prints decisions and does not rotate logs or update the state file. Look for the exact path and whether it is missing, empty, not due, or rejected.
What you should see · The debug output names the exact log and gives a reason for rotating or skipping it.
If you see something else · If the log is missing from the output, check that the active configuration includes its stanza. For an explicit error, fix that error and repeat debug mode before triggering a rotation.
sudo logrotate --debug /etc/logrotate.confCheck whether the application reopened the new log
If the archive exists but the active file stays unchanged, look for an application process holding the rotated file open. Replace the sample suffix with the real archive name. Compare the expected service account and file ownership with the service’s supported reopen behavior.
sudo lsof -- /var/log/myapp/app.log /var/log/myapp/app.log.1Correct the cause and check again
Restore the approved schedule if missing. For configuration errors, correct the identified path, ownership, or rule and rerun debug mode. When rename-and-create rotation succeeds but the process keeps writing to the old inode, use the vendor-supported reopen or reload mechanism. Avoid switching to copytruncate without reviewing its possible log-loss window.
Verify on the next approved rotation
Check the scheduler result and archive. Trigger an ordinary approved request and confirm new entries reach the active file and any collector. If the change breaks writes or forwarding, restore the previous approved configuration and use the application’s supported recovery procedure.
Decide What to Do Next
| Finding | Next action |
|---|---|
| Debug reports the log is not due | Check the time or size rule against the actual schedule. |
| Service reports an error | Review that invocation’s message, including configuration and directory permissions. |
| Archive grows while active file stays quiet | Check the service’s open descriptors and reopen behavior. |
References
Your feedback keeps these production procedures accurate and battle-tested.