Configuring Logging
Nov 11, 2025
Using systemd-journald
Useful commands
systemctl status name.unit # easy access to the latest log messages
journalctl # prints entire journal (important in red)
journalctl -p err # shows only messages with a priority error and higher
journalctl -f # shows the last 10 lines and follows
journalctl -u name.unit #
journalctl --since "-1 hour"
journalctl --since today
journalctl -o verbose #
journalctl -b # shows current boot log
journalctl -xb # add explanation to boot log messages
journalctl --list-boots # shows all boots that have been logged (persistent journal only)
journalctl -b 3 # shows messages from the third boot log only
Preserving the systemd journal
Check current journal settings
journalctl | grep -E 'Runtime Journal|System Journal'
Make the system journal logs persistent
grep 'Storage=' /usr/lib/systemd/journal.conf
mkdir /var/log/journal
systemctl restart systemd-journal-flush.service
ls /var/log/journal
Rsyslog
Logrotate
Knowledge Check
- Why are systemd logs non persistent by default?
- Where are the systemd journal settings?
- What are the storage options for the systemd journal?
- How often are log files rotated by default?
- How much of the filesystem size can be used by logs by default?
- How much of the filesystem free size can be used by logs by default?
- Where is the configuration file for rsyslog?
- How should you modify the rsyslog configuration?
- What does each logger line contain?
- Where are the log rotate configuration files
Answers
- Persistent logs are handled by the rsyslog service
- /usr/lib/systemd/journal.conf
- Storage options
- auto: will write persistent logs to /var/log/journal if the directory exists, otherwise will write volatile logs to /run/log/journal
- persistent: stores journals in /var/log/journal
- volatile: stores journals in the temp /run/log/journal directory
- none: doesn’t use any storage for the journal at all
- Log files are rotated monthly by default
- 10%
- 15%
- /etc/rsyslog.conf
- Add drop-in files to /etc/rsyslog.d
- Each logger line contains
- facility
- severity
- destination
- /etc/logrotate.conf and /etc/logrotate.d
Lab Exercise
- Make sure the systemd journal is persistent
- Create an entry in rsyslog that writes all messages with a severity of error or higher to /var/log/error
- Ensure that /var/log/error is rotated on a monthly basis, and the last 12 logs are kept before they are rotated out
Solution
-
—
mkdir /var/log/journal systemctl restart systemd-journal-flush.serviceor
mkdir /var/log/journal journalctl --flush -
—
echo "*.err /var/log/error" >> /etc/rsyslog.d/error.conf systemctl restart rsyslog logger -p err "error message" tail /var/log/error -
/etc/logrotate.d/error
/var/log/error { monthly rotate 12 }
- Clint Jordan