Skip to content

Lesson 7 of 9 · 25m

journald Deep Dive: Structure, Storage, and Useful Queries

What journald gives you beyond /var/log text files: indexed fields, per-unit history, persistence, rotation, forwarding, and queries that actually shorten incidents.

Text files made log inspection familiar, not necessarily good. journald's real value is structure: every entry carries indexed metadata — unit, PID, UID, boot ID, priority, executable — so you can ask precise questions during incidents instead of grepping a swamp.

Read like an operator

journalctl -u metrics-api.service --since "2 hours ago"
journalctl -u ssh.service -p warning..err
journalctl -b -1 -e
journalctl -k --since today

The muscle-memory flags matter: -b selects a boot, -u selects units, -p selects priority, -k selects kernel messages, -e jumps to the end, and --since/--until bound the time window.

Fields beat text matching:

journalctl _SYSTEMD_UNIT=metrics-api.service _PID=4213
journalctl SYSLOG_IDENTIFIER=sshd --since yesterday
journalctl -o json-pretty -u metrics-api.service -n 1

The JSON output shows exactly which metadata exists for your entries.

stdout is a feature, not a mistake

A service does not need its own log file merely because tradition says so. If it prints structured logs to stdout, journald captures them with unit identity and retention policy:

[Service]
StandardOutput=journal
StandardError=journal
SyslogIdentifier=metrics-api

JSON lines work well because downstream pipelines can parse them while journald retains the complete message. Do not double-log to stdout and files unless you enjoy paying for disk twice.

Persistent versus volatile journals

If /var/log/journal exists, logs persist across reboot. Otherwise journald stores them in /run/log/journal, which disappears on reboot. Check before assuming:

ls -ld /var/log/journal
journalctl --disk-usage

Configure retention in /etc/systemd/journald.conf:

[Journal]
Storage=persistent
SystemMaxUse=1G
SystemKeepFree=2G
MaxFileSec=1day

Retention is a capacity decision. Unbounded journals eventually become the outage you were trying to debug.

Rate limits and forwarding

journald rate-limits noisy services. If you see Suppressed 1024 messages, silence in the journal does not mean the application stopped logging. Tune RateLimitIntervalSec and RateLimitBurst deliberately — or better, fix the chatty application.

journald is the local collection layer, not a replacement for centralized logging. Forward through your existing agent, but keep enough local retention for the first hour of an incident; central pipelines often fail exactly when networks fail.

Field notes

  • Users need appropriate journal permissions, commonly membership in systemd-journal.
  • Kernel messages are not unit-tagged; combine -k with boot windows for early failures.
  • journalctl --since "-10 min" is valid and useful.
  • Do not abuse journald fields as a metrics system; use structured application messages plus a real metrics pipeline.

Was this lesson helpful?

Sign in to rate