Logs are the system's diary. Services, the kernel and login tools record what they did and what went wrong. When something breaks, they are usually the first place to look.
Who writes the logs
Most Linux distributions today use systemd, whose logging service is systemd-journald. It collects messages from the kernel, from services' standard output and error, and from the traditional syslog interface. It stores them in a binary journal.
Many systems also run a syslog daemon, commonly rsyslog, which writes plain text files under /var/log. Some distributions install it by default and others rely on the journal alone. Some programs, such as web servers, write their own files.
Reading the journal
$ journalctl -n 3
Jan 05 16:29:01 web01 CRON[4573]: pam_unix(cron:session): session closed for user root
Jan 05 16:30:50 web01 dhclient[700]: XMT: Solicit on eth0, interval 119360ms.
Jan 05 16:31:04 web01 systemd[1]: Started nginx.service.Each line shows time, host, the program with its process ID, and the message. Useful filters:
journalctl -u nginxshows one unitjournalctl -bshows the current bootjournalctl -ffollows new messagesjournalctl -p errshows errors and worsejournalctl --since "1 hour ago"limits by time
Without root or membership of a suitable group (such as adm or systemd-journal), you may see only your own messages. Use sudo if output seems thin.
Is the journal kept?
Whether the journal survives a reboot depends on configuration. With the common Storage=auto setting, it is saved to disk if /var/log/journal exists, and otherwise kept in memory under /run/log/journal.
List the boots the journal knows about:
$ journalctl --list-bootsText files
$ ls /var/logYou can read text logs with less, follow them with tail -f and search them with grep. Names differ between distributions, and later lessons cover the main ones.
Try it
Run journalctl -b -p warning and read a few lines. Then run ls -l /var/log and see which files changed recently. Check whether /var/log/journal exists on your system.
Check your understanding
System Logging
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.