journald & Reading Logs
systemd in Depth
Chapter 6 · journald & Reading Logs
systemd1-1's own warn-box named journald as part of systemd's broader scope beyond process supervision. This chapter is that promised depth — and it's also the single-host counterpart to obs1-7's own centralized logging material.
What journald Actually Is
systemd's own built-in logging daemon. It automatically captures stdout/stderr from every unit systemd manages, plus kernel messages, plus anything using the standard syslog() call — with no separate logging setup required for a systemd-managed service. Storage is structured and indexed, not plain text like a traditional /var/log/*.log file — queryable directly by unit, priority, or time range, without reaching for grep/awk gymnastics.
journalctl — The Basic Query Tool
-u myapp ties directly to systemd1-3's own worked example. -f is genuinely comparable to tail -f on a traditional log file. -b -1 is a real, practical tool for diagnosing a crash or unexpected reboot after the fact — the previous boot's own logs, isolated from everything since.
Persistent vs. Volatile Logging
By default on many systems, the journal lives in /run/log/journal/ — RAM-backed, volatile, wiped completely on reboot. This has a real, practical consequence: journalctl -b -1 only works at all if persistent storage is actually configured; without it, the previous boot's logs are simply gone.
Creating /var/log/journal/ with correct ownership is the actual, real-world trigger that switches journald into persistent mode automatically — logs now survive reboots. This matters directly for the same reason ws1's own security material cared about logging at all: a system with only volatile logs loses everything the moment it's rebooted, a real, practical gap for any kind of incident investigation after the fact.
Priority Filtering
The classic 8-level syslog priority scale — emerg, alert, crit, err, warning, notice, info, debug, ordered from most to least severe. -p err shows entries at error level or more severe — the scale is ordered, so this filters "at least this severe," not "exactly this level." A real, practical way to find genuinely serious issues in a noisy, chatty log without reading every routine info-level line.
The Single-Host Counterpart to obs1-7's Own Centralized Logging
obs1-7 covered structured logging and centralized aggregation (Loki) across many hosts and services, at real scale. journald solves a genuinely related but narrower problem — one host's own logs, structured and queryable, with no separate aggregation system required at all. The same underlying idea — structured, queryable logs beat unstructured, grep-able text files — applies at both scales, just with different tooling for different scopes. Real production setups often use both: journald locally on each host, with an agent (the same DaemonSet-based approach obs1-10 described) shipping journal entries onward to centralized storage. journald isn't replaced by Loki — it's frequently the local source a Loki-equivalent agent reads from in the first place.
| Format | Queryable by field? | Persistent by default? | |
|---|---|---|---|
| Traditional /var/log/*.log | Plain text | No — grep/awk required | Yes |
| journald | Structured, indexed, binary | Yes — by unit, priority, time, ... | No — must be enabled |
journalctl -u myapp -p err -b combines everything in this chapter — one specific unit, error-severity-or-worse only, current boot only. Exactly the kind of narrow, deliberate query you'd actually run mid-incident, rather than scrolling through the entire journal by hand.
journalctl --disk-usage shows current size; journalctl --vacuum-size=500M (or --vacuum-time=) actually reclaims space. A real, practical maintenance task worth knowing about before disk space becomes a genuine problem, not after.
Hands-On Exercises
Write the journalctl command to view only error-or-worse log entries for a unit named "backup-agent" from the current boot, matching this chapter's own combined example pattern.
📄 View solutionA server unexpectedly rebooted overnight. An administrator runs journalctl -b -1 the next morning to investigate, but gets no results at all. Explain the most likely cause.
📄 View solutionExplain, using this chapter's own material, why a real production setup might reasonably run both journald locally and ship logs to a centralized system like obs1-7's own Loki, rather than choosing one or the other.
📄 View solutionChapter 6 Quick Reference
- journald automatically captures unit stdout/stderr, kernel messages, and syslog() calls — structured, indexed, no separate setup needed
- -u UNIT, -f (follow), -b (current boot), -b -1 (previous boot) — the core journalctl flags
- Volatile by default (/run/log/journal/, wiped on reboot); creating /var/log/journal/ enables persistent storage
- -p LEVEL filters to that severity or worse, using the 8-level syslog scale
- journald is the single-host counterpart to obs1-7's own centralized aggregation — often the local source a Loki-equivalent agent reads from
--disk-usage/--vacuum-size=/--vacuum-time=— real, necessary journal maintenance