Course contentsShow
← Linux
Lesson 609 of 1,8196. Systemd Internals and Unit OrchestrationFree lesson

Filtering Logs by Metadata

Query logs using journalctl filters to isolate events by boot, service, or priority.

In this lesson, you will learn how to navigate the vast amount of system information collected by journald by using specific metadata filters to pinpoint the exact logs you need.

When your system generates thousands of lines of logs, reading them chronologically is inefficient. Because journald stores logs in a structured binary format, it automatically indexes metadata such as the service name, the boot session, and the importance (priority) of the message. We use the journalctl command to query these specific fields.

Filtering by Boot

If you are troubleshooting an issue that started after a reboot, you don’t want to sift through weeks of historical data. You can isolate logs from the current or previous boot using the -b flag:

# View logs from the current boot
journalctl -b

# View logs from the previous boot
journalctl -b -1

Filtering by Service

To see only the logs generated by a specific unit (like the web server), you can use the -u flag. This ignores all unrelated system noise:

journalctl -u nginx.service

Filtering by Priority

System messages are assigned a "priority" level, ranging from 0 (emergency) to 7 (debug). If you only want to see critical errors that might indicate why a service failed, use the -p flag followed by the priority level or name:

# Show only errors and higher-severity messages (0-3)
journalctl -p err

Combining Filters

The real power of journalctl comes from stacking these filters. By combining them, you can perform very precise diagnostics. For instance, to see all errors from your web server since the last boot, you would run:

journalctl -u nginx.service -b -p err

This approach shifts your workflow from "searching for a needle in a haystack" to "retrieving exactly the data you requested." By utilizing these metadata flags, you can isolate service failures or hardware issues in seconds rather than minutes.

Key Takeaway: Use journalctl flags like -b for boot sessions, -u for units, and -p for priority to extract actionable intelligence from your system logs instantly.