LINUX-PRODUCTION Contents

journald Basics (Reading, Filtering, Retention)

Use journalctl effectively and configure retention without losing critical data.

On this page

Why journald Matters in Production

In production, logs are your timeline. systemd-journald centralizes logs from services, kernel, and system components. If you do not know journalctl, you will waste time tailing random files and miss critical context.

What journald Collects

  • systemd service stdout/stderr (when configured)
  • Kernel messages
  • System services logs
  • Boot and shutdown events

This means you can correlate incidents across services using a single interface.

Basic Queries You Must Know

Logs for a Service

journalctl -u myapp -n 200 --no-pager

Follow Logs (Like tail -f)

journalctl -u myapp -f

Logs Since a Time Window

journalctl -u myapp --since "10 minutes ago" --no-pager
journalctl -u myapp --since "2026-02-24 18:00:00" --no-pager

Logs for Current Boot

Extremely useful after reboot:

journalctl -b --no-pager
journalctl -b -u myapp --no-pager

Previous Boot (Why Did It Crash?)

journalctl -b -1 --no-pager

Filter by Priority (Errors Only)

Priorities:

  • 0 emerg
  • 1 alert
  • 2 crit
  • 3 err
  • 4 warning
  • 5 notice
  • 6 info
  • 7 debug
journalctl -u myapp -p err --no-pager
journalctl -p warning..err --no-pager

Structured Fields: More Than Text

journald stores metadata fields like:

  • _PID, _UID
  • _SYSTEMD_UNIT
  • _COMM
  • MESSAGE

View fields:

journalctl -u myapp -o verbose | head -n 60

Output Formats

Useful formats:

  • -o short-iso (readable timestamps)
  • -o json (machine parsing)
journalctl -u myapp -o short-iso --no-pager
journalctl -u myapp -o json --no-pager | head

Disk Usage and Retention

In production, journals can grow. Check size:

journalctl --disk-usage

Vacuum old logs:

journalctl --vacuum-time=7d
journalctl --vacuum-size=1G

Do not vacuum blindly during incidents; preserve evidence first.

Persistent vs Volatile Journals

Some systems keep logs only in memory (lost on reboot). If you want persistence, ensure:

/var/log/journal

And journald config:

/etc/systemd/journald.conf
Storage=persistent

Rate Limiting

During crash loops, logs can flood. journald has rate limiting to protect the system. If you see missing logs, rate limiting may be dropping messages. Check journald settings:

  • RateLimitIntervalSec
  • RateLimitBurst

Incident Workflow with journalctl

A reliable workflow:

  • Check unit status
  • Check logs for current boot
  • Check last 10 minutes and errors only
  • Check previous boot if needed
systemctl status myapp --no-pager
journalctl -b -u myapp -n 200 --no-pager
journalctl -u myapp --since "10 minutes ago" -p err --no-pager

Common Production Mistakes

  • Relying only on /var/log files and missing unit stdout/stderr
  • Not using -b / -b -1 after reboots
  • Letting journals grow without retention policy
  • Vacuuming logs during an incident (destroying evidence)
  • Ignoring rate-limiting signs during crash loops

Mental Model

journald is your central timeline. Use it like an event database: filter by unit, time, priority, and boot. Production debugging becomes faster when you stop hunting logs across the filesystem.

Production Checklist

  • Know journalctl -u, -f, --since, -b, -b -1
  • Use priority filters (-p err) during incidents
  • Set retention policy (vacuum-time/size)
  • Ensure persistent storage if required
  • Be aware of rate limiting during crash loops