Drill: Filter Journal Entries by Time, Unit, and Priority¶
Goal¶
Use journalctl to filter systemd journal entries by time range, service unit, and log priority level.
Setup¶
- A Linux system running systemd with journald active
- Root or a user in the
systemd-journalgroup
Commands¶
View logs from the last hour:
View logs in a specific time window:
Filter by a specific unit (service):
Filter by priority (0=emerg through 7=debug):
journalctl -p err # show err and above (crit, alert, emerg)
journalctl -p warning..err # show warnings through errors only
Combine filters for targeted investigation:
Follow logs in real time for a unit:
Output as JSON for scripting:
What to Look For¶
- Timestamps narrow the output to your incident window
- Priority filters eliminate noise from info/debug messages
- Unit filters isolate a single service's logs from the full journal
- JSON output includes metadata fields not shown in default format
Common Mistakes¶
- Forgetting quotes around time expressions like
"1 hour ago" - Using
-p infowhen you want to reduce noise (info shows everything info and above) - Not using
--no-pagerin scripts, causing journalctl to hang waiting for input - Confusing
--since today(midnight) with--since "1 hour ago"
Cleanup¶
No cleanup needed. journalctl is read-only by default.