devutils/ATFQ/book ATFQ git

Part II · Your system

26.3 Log rotation and logs that fill the disk

alsologrotatelog rotationjournal sizesystemmaxusevacuumjournalctl --vacuum-sizejournalctl --disk-usagelog too biglogs filling diskcopytruncatedocker logs size

TL;DR

  • journald limits itself: by default up to 10 % of its filesystem, at most 4 GiB. SystemMaxUse= changes it.
  • logrotate handles text logs: on a schedule it renames the file, starts a new one, compresses old ones and deletes the oldest.
  • A log that grows without limit usually has no rotation rule, or a program writing too much.
journalctl --disk-usage
sudo journalctl --vacuum-size=500M      # shrink the journal now
sudo logrotate -d /etc/logrotate.conf   # dry run: what would rotate

On your machine

alice@laptopexample
$ atfq 26.3
  Journal   on disk (/var/log/journal): kept across reboots · 300 B in 2
            files
  Settings  SystemMaxUse=500M
  Syslog    rsyslog also writes text files in /var/log
  Rotation  2 rules in /etc/logrotate.d
  Biggest   /var/log/syslog 4.9 KiB · /var/log/nginx/access.log 2.9 KiB ·
            /var/log/auth.log 1.2 KiB

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

What does a logrotate rule look like?
/var/log/myapp/*.log {
    weekly
    rotate 4
    compress
    missingok
    postrotate
        systemctl reload myapp
    endscript
}

Four weeks are kept, compressed, then deleted. A systemd timer (or cron) runs logrotate daily; each rule decides how often it acts.

Why do journald limits sometimes not apply?

They count only the journal's own files, archived ones first: the file being written stays until it's rotated. Limits are checked as it writes, so after lowering SystemMaxUse=, run ⚠ --vacuum-size or restart journald to shrink at once.

Commands
journalctl logrotate lsof
Paths
/etc/logrotate.conf /etc/logrotate.d/ /etc/systemd/journald.conf
See also
26. Logs
26.2 Where logs go: journald, syslog and /var/log
13.4 Links, inodes and "disk full"