Sub topic 1
Where Logs Come From: journald, Syslog and Files
Prerequisites
This chapter assumes that you can use the Linux command line, edit files with sudo, inspect systemd units with systemctl, and recognize common paths under /var/log. You should also know that a service is a background process managed by the operating system.
The Three Main Log Sources
Linux logs usually come from one of three places:
- The systemd journal is a structured database managed by
systemd-journald. It receives messages from the kernel, system services, and applications. - Syslog is a message format and delivery convention. It defines fields such as a facility, severity, timestamp, hostname, and message. Programs such as
rsyslogimplement syslog collection and forwarding. - Plain log files are files written directly by applications. Common examples include
/var/log/nginx/access.logand/var/log/auth.log.
These sources can overlap. A service may write to standard output, which systemd sends to journald. Another service may open /var/log/app.log itself. rsyslog can read messages from journald and write selected messages to traditional files or forward them to another server.
Reading the Journal
Use journalctl to query the journal instead of opening its database files directly:
# Show recent messages from the current boot
sudo journalctl -b
# Follow new messages as they arrive
sudo journalctl -f
# Show messages for one service
sudo journalctl -u ssh.service --since "today"Journal entries contain metadata that is useful for filtering, such as the systemd unit, process ID, boot ID, and priority. The journal can be stored in memory or on disk. Persistent storage normally uses /var/log/journal, but the directory may not exist on a newly installed system.
A journal entry is not automatically a text file. If another tool needs traditional syslog records, journald can pass messages to a syslog daemon such as rsyslog.
Syslog Fields and Destinations
A syslog message has a facility, which identifies the source category, and a severity, which describes urgency. For example, authpriv commonly identifies protected authentication messages, while daemon identifies background services. Severity ranges from debug through emerg.
rsyslog applies rules to these messages. A rule can write to a file, send a message over the network, or discard it. Its configuration commonly lives in /etc/rsyslog.conf and /etc/rsyslog.d/.
| Source or component | Typical role | Example |
|---|---|---|
| journald | Collects structured local messages | `journalctl -u nginx` |
| rsyslog | Routes and forwards syslog messages | `/etc/rsyslog.d/` |
| Application file | Stores application-defined text logs | `/var/log/myapp/app.log` |
A Practical Investigation
When a service fails, first check its journal:
sudo systemctl status myapp.service
sudo journalctl -u myapp.service -b --no-pagerIf the service writes its own file, inspect that file separately. If messages should be forwarded, check rsyslog's status and configuration. This separation helps identify whether the problem is message creation, local storage, routing, or network delivery.
Exercise
Why might a message appear in journalctl but not in /var/log/syslog?
Show answer
journald may have collected it without forwarding it to rsyslog, or rsyslog may have filtered it or written it to a different destination.