← All technical notes

Systems / Field notes

Managing Linux system logs

Published

Logs are an operational resource. They help explain failures, audit changes and reconstruct incidents, but unlimited retention can turn an ordinary application fault into a storage outage.

Find the main consumers

Inspect filesystem capacity, the journal’s disk usage and large log directories. A single verbose service may dominate storage even when the rest of the system is quiet. Distinguish the systemd journal from conventional log files, application-specific logs and compressed archives.

df -h /
journalctl --disk-usage
sudo du -h -d 1 /var/log | sort -h
journalctl -p warning -b --no-pager -n 50
Service events
Journal or log file
Rotation / retention
Archive or expiry
Log retention has to account for active files and archived data.

Set a realistic journal budget

On a small server, choose a journal limit and free-space reserve based on disk capacity, event rate and incident-response requirements. The following is an illustrative journald configuration, not a universal recommendation. Review existing settings and overrides first.

[Journal]
SystemMaxUse=100M
SystemKeepFree=1G
MaxRetentionSec=30day

Journal limits are not a guarantee that every event survives for the specified period. High message rates may shorten retention, and active files can affect reported usage. Rotation and vacuuming remove eligible archived journals; preserve evidence before performing cleanup.

Traditional logs need their own policy

Logrotate handles conventional files using rules for size, time, retention and compression. A maximum size is checked when logrotate runs, not continuously. Review the timer frequency if a noisy service can fill the disk between runs. Use debug mode to inspect the proposed actions before changing a policy.

sudo logrotate -d /etc/logrotate.conf
systemctl list-timers logrotate.timer

Reduce unnecessary verbosity

Use debug logging during a bounded investigation, then return to an appropriate production level. Retain relevant security and error events. Monitor disk space separately so logging failures can be detected even when the log itself stops growing.

Control the source of excessive logging as well as its retention.

Further reading