Skip to main content
RunBook Academy

LinuxVIII · Logging and journaldLogging architecture

Linux logging architecture — kernel, journald, syslog

Foundation⏱ ~10 minbashjournalctldmesgcat

What you'll learn

  • Trace a log message from producer to consumer
  • Distinguish kernel logs, journald, syslog, and application logs
  • Identify which log destination a given service uses
  • Plan for log retention and central shipping

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

A Linux system produces logs from at least four sources. Each has its own destination, format, and lifetime. Understanding them is the foundation of every operational diagnostic.

The four layers

flowchart LR
  K["Kernel<br/>printk / /dev/kmsg"]
  S["System services<br/>sd_notify / syslog"]
  A["Applications<br/>stdout/stderr / files"]
  J["journald<br/>binary journal"]
  Y["syslog<br/>rsyslog / syslog-ng"]
  F["Log files<br/>/var/log/"]

  K --> J
  S --> J
  S --> Y
  A --> Y
  A --> F
  J --> SI["central shipper"]
  Y --> SI
  F --> SI
LayerProducerDefault destinationLifetime
Kernelprintk, drivers, BPF/dev/kmsg, journaldUntil journal rotates or host reboots
journaldsystemd-managed servicesbinary journal at /var/log/journal/Until rotated by SystemMaxUse
syslogrsyslog / syslog-ng/var/log/auth.log, /var/log/syslog, /var/log/secureUntil logrotate compresses or deletes
Application filessshd, nginx, mysqlconfigured per applicationuntil logrotate or manual cleanup
Read-only / Safelog destinations
$ journalctl --list-boots; ls -la /var/log/journal/; ls -la /var/log/
-1 1234567890abc... Mon 2026-08-04 11:23:45 UTC—Mon 2026-08-04 11:24:00 UTC
0 abcdef123456... Mon 2026-08-04 11:24:00 UTC—Mon 2026-08-09 12:00:00 UTC

6 -rw-r-x---+ 1 root root 12345678 Aug  9 12:00 /var/log/journal/user-1000.journal
drwxr-xr-x  2 root root      4096 Aug  9 12:00 /var/log/journal/remote/

-rw-r-----  1 root adm    12345 Aug  9 12:00 /var/log/auth.log
-rw-r-----  1 root syslog  67890 Aug  9 12:00 /var/log/syslog
-rw-r-----  1 root root   234567 Aug  9 12:00 /var/log/kern.log
drwxr-xr-x  2 root root    4096 Aug  9 12:00 /var/log/nginx/

Illustrative output

Kernel logs: dmesg and /dev/kmsg

The kernel logs through printk to a ring buffer. On modern systems, journald reads the ring buffer (via /dev/kmsg) into the journal. dmesg is a convenience command for reading the ring buffer; on systemd-managed systems, prefer journalctl -k.

Read-only / Safedmesg vs journalctl -k
$ dmesg | tail -5; journalctl -k --no-pager | tail -5
[    5.234] systemd[1]: Starting Journal Service...
[    5.456] sshd[1234]: Server listening on 0.0.0.0 port 22.
[    5.789] chronyd[567]: Selected source 169.254.169.254 (PHC0)
...

Illustrative output

journald — systemd’s logging service

journald is the system service that captures log messages from every systemd-managed unit. It writes to a binary journal in /var/log/journal/. The journal is queryable via journalctl with rich filtering.

journalctl -u sshd                       # by unit
journalctl -p err                        # by priority
journalctl -b                            # since boot
journalctl --since "1 hour ago"          # by time
journalctl -f                            # follow (tail -f equivalent)
journalctl -k                            # kernel messages
journalctl -u sshd -p err                # combine filters
Read-only / Safejournalctl unit filter
$ journalctl -u sshd --since '1 hour ago' --no-pager | tail
Aug  9 11:23:45 host sshd[12345]: Accepted publickey for alice from 10.0.0.5 port 51234 ssh2: RSA SHA256:abc...
Aug  9 11:24:12 host sshd[12345]: pam_unix(sshd:session): session opened for user alice by (uid=0)
Aug  9 11:30:01 host sshd[12345]: Failed password for invalid user admin from 203.0.113.45 port 51234 ssh2

Illustrative output

syslog — the traditional text logging

Traditional syslog writes text records to /var/log/ files organised by facility and priority:

FacilityOrigin
auth / authprivAuthentication events
kernKernel messages (when not using journal-only)
daemonSystem daemons (without systemd)
mailMail subsystem
userUser-level messages
local0-local7Application-defined
PriorityMeaning
emerg / panicSystem unusable
alertImmediate action required
critCritical conditions
errError conditions
warning / warnWarning conditions
noticeNormal but significant
infoInformational
debugDebug-level messages
Read-only / Safelogger
$ logger -p auth.warning -t myapp "failed login attempt for admin"; tail -1 /var/log/auth.log
Aug  9 12:00:01 host myapp: failed login attempt for admin

Illustrative output

Application files — the unstructured layer

Some applications do not write to syslog or journald directly. They write to files under /var/log/<application>/:

  • nginx: /var/log/nginx/access.log, error.log
  • mysql: /var/log/mysql/error.log
  • PostgreSQL: /var/log/postgresql/
  • Apache: /var/log/apache2/, /var/log/httpd/

These files are managed by logrotate; rotation and retention are configured in /etc/logrotate.d/<application> or /etc/logrotate.conf.

Read-only / Safelogrotate.d
$ ls /etc/logrotate.d/
apt
dpkg
nginx
rsyslog
sshd
...

Illustrative output

The default flow

flowchart TB
  APP["Application / service"]
  SD["systemd service"] --> J["journald"]
  K["Kernel"] --> J
  J --> JS["/var/log/journal/"]
  J --> SH["Forward to rsyslog"]
  APP --> SY["Traditional syslog call"]
  SY --> RS["rsyslog / syslog-ng"]
  RS --> RL["/var/log/auth.log, syslog, kern.log"]
  APP --> AF["/var/log/APPNAME/*.log"]

Knowledge check

Knowledge check · 3 questions

  1. Q1. Where does journald store its logs by default?

  2. Q2. The default journal size limit is not a flat 4 GB, so on a host with a small /var the journal is capped well below that.

  3. Q3. Which of the following are correct logging architecture practices? Select all that apply.

Passing score: 75%. Answers are checked in this browser.