Skip to content

journalctl filtering — the practical patterns for incident response on a systemd host

The journalctl filters that turn a noisy systemd log into a focused incident timeline — unit, priority, time range, structured field matchers, and the export patterns that survive grep.

The first ten minutes of a Linux incident often come down to “what was the host doing right before things broke.” On any systemd box, journalctl already has the answer — every service log, every kernel event, every cron run is in the journal with structured fields. The problem is that journalctl -f without filters is a wall of noise. This article is the reference card of filters we use during triage, plus the patterns for exporting a clean timeline you can share with a customer or attach to a post-mortem.

How to verify

Before relying on the journal, confirm it is persistent (not in /run), has reasonable retention, and that your user can read other services’ logs.

journalctl --header | head -5
sudo journalctl --disk-usage
sudo journalctl --verify 2>&1 | tail -5
ls -ld /var/log/journal /var/log/journal/*/ 2>/dev/null
id | grep -Eo 'systemd-journal|adm'
grep -E '^(Storage|SystemMaxUse|MaxRetentionSec)' /etc/systemd/journald.conf

If /var/log/journal/ does not exist, the journal is in-memory only and disappears on reboot — fix that before doing anything else (sudo mkdir -p /var/log/journal && sudo systemctl restart systemd-journald).

What’s happening

systemd-journald writes every line received from a service (via STDOUT/STDERR, syslog forwarding, or sd_journal_send calls) into a binary journal file along with structured metadata: which unit emitted it, which PID, which UID, the priority level, _BOOT_ID, _HOSTNAME, and any fields the application chose to attach. journalctl reads those files and lets you filter on any of those fields.

Two filter axes do most of the work. By unit (-u) narrows the stream to one service or a glob of services. By priority (-p) narrows by severity (emerg, alert, crit, err, warning, notice, info, debug). Layered on top, time-range filters (--since, --until, --boot) crop to the incident window. Finally, field matchers (FIELD=value as positional arguments) filter on any structured field — the killer feature for application logs that emit MESSAGE_ID or REQUEST_ID.

The procedure

  1. Pin the incident window first. Everything else is filtering inside this window.

    journalctl --since "2026-06-02 14:30:00" --until "2026-06-02 15:00:00"
    journalctl --since "1 hour ago"
    journalctl -b -1       # all logs from the previous boot
    journalctl --list-boots | head
  2. Narrow to a unit (or a group of them). -u takes a glob — useful when the service is sharded into worker-0.service, worker-1.service, etc.

    journalctl -u nginx
    journalctl -u 'worker-*.service'
    journalctl -u nginx -u postgresql        # multiple units
  3. Filter by priority. -p err means err and worse; -p 'err..crit' is a range.

    journalctl -u nginx -p err
    journalctl --since "1 hour ago" -p warning
    journalctl -p emerg..crit -b              # critical events this boot
  4. Use field matchers for structured logs. Anything an application emits via sd_journal_send (or any of the language bindings) is queryable.

    # All logs from a particular request ID
    journalctl REQUEST_ID=abc-123 --since "10 min ago"
    # Logs from a specific binary (resolved through _COMM)
    journalctl _COMM=postgres -p err
    # Logs from a single PID (useful after the process is gone)
    journalctl _PID=12345
    # Logs tied to a systemd transient unit
    journalctl _SYSTEMD_UNIT=session-c1.scope

    journalctl -F FIELDNAME lists all values seen for that field — the discovery move when you do not know what to query.

  5. Combine for the incident view. A common triage one-liner: “all warnings or worse, from nginx and php-fpm, in the last 15 minutes, with kernel messages.”

    journalctl -u nginx -u php-fpm -k -p warning --since "15 min ago" -o short-iso

    -k adds kernel messages (OOM kills, network resets) that often explain a userspace error.

  6. Export a clean timeline. Two output formats matter. short-iso for human reading and grep; json-pretty for piping into jq.

    # Human-readable timeline, copy/pasteable into a post-mortem
    journalctl -u myapp --since "2026-06-02 14:00" --until "2026-06-02 15:00" \
      -o short-iso --no-pager > /tmp/incident-myapp.log
    
    # Structured fields for analysis
    journalctl -u myapp --since "1 hour ago" -o json | \
      jq -c '{t: .__REALTIME_TIMESTAMP, msg: .MESSAGE, level: .PRIORITY, req: .REQUEST_ID}' \
      > /tmp/incident-myapp.ndjson

    __REALTIME_TIMESTAMP is microseconds since epoch — divide by 1,000,000 for seconds.

  7. Tail with filters. -f works with any filter, so triage starts narrow instead of hand-rolling grep against -f.

    journalctl -u nginx -p warning -f
    journalctl -u 'worker-*' -f --no-hostname --since "now"

Operational notes

  • A non-persistent journal (/run/log/journal) means the next reboot loses everything; this is the default on minimal Ubuntu cloud images.
  • Without --no-pager, journalctl invokes less and most CI tools hang; always pass it in scripts.
  • journalctl -p err excludes warning — operators expecting “errors and warnings” should use -p warning.
  • A user filter like _UID=1000 requires read permission across the whole journal; add the operator to systemd-journal group to make this usable interactively.
  • Application fields are case-sensitive (REQUEST_ID, not request_id) and use uppercase by convention; libraries sometimes emit lowercase and the matcher silently returns nothing.

For getting application logs into the journal as structured fields, see systemd-cat-log-injection. For shipping the resulting journal entries to Loki, see promtail-log-shipping.


Stack Harbor runs the journalctl filters above as part of incident triage in the managed operations tier — every host’s journal is persistent, retention is sized to the audit window, and the patterns live in client-specific runbooks so triage starts from a filter, not a tail -F.