Digital Tutorials 5 min read

journalctl in Linux: How to Read System Logs for Troubleshooting

A practical guide to using journalctl on Linux for reading systemd logs, filtering services and errors, monitoring events, and managing log retention safely.

journalctl in Linux: How to Read System Logs for Troubleshooting

When a Linux server slows down, services fail to start, or applications suddenly stop, system logs are often the best place to begin investigating the cause. On Linux distributions that use systemd, the journalctl command helps you read records collected by systemd-journald without having to open multiple log files manually.

This guide covers the most useful commands for daily inspection, how to narrow down search results, and important considerations to keep troubleshooting safe.

What Is journalctl?

journalctl is a utility for reading logs from the systemd journal. These records can come from the kernel, systemd services, and applications that send messages through supported logging mechanisms. The journal format stores metadata such as timestamps, service units, and message priorities, allowing results to be filtered as needed.

Not all Linux systems use systemd. If the device uses a different init system or logging framework, this command may not be available or may not display all application logs. Access to some records also depends on user privileges and distribution configuration.

1. Reading Recent Logs and Logs Since Boot

Run the following command to view journal entries:

journalctl

The output typically opens in a pager for easy navigation. Press q to exit. To view messages from the current boot process, use:

journalctl -b

If the journal stores boot history, the -b -1 option displays logs from the previous boot. Available boot numbers can be checked with:

journalctl --list-boots

Older boot history is not always available. On systems that only store the journal in memory, records may be lost after reboot. Therefore, do not assume that missing old logs prove a problem never occurred.

2. Filtering by Service

If a specific service is experiencing issues, filter by unit name to avoid mixing results with other messages. Example for Nginx:

journalctl -u nginx

To limit results to the last hour:

journalctl -u nginx --since "1 hour ago"

Unit names must match what the system uses. If unsure, the service list can be checked with systemctl list-units --type=service. Some applications write logs to their own files or to other logging systems, so their messages may not appear in the journal.

3. Finding Warning and Error Messages

When logs are too lengthy, start with messages at warning priority or higher:

journalctl -p warning

Journal priorities range from emergency to debug. Selecting warning includes warnings and more severe levels. To see messages from today, combine with a time filter:

journalctl -p warning --since today

Priority filters can help speed up inspection, but do not replace reading context. Lower-priority messages sometimes explain events that preceded an error, while some applications assign priority levels inaccurately.

4. Following Logs in Real Time

To monitor what happens when a service restarts or new requests arrive, use follow mode:

journalctl -u nginx -f

This command continuously displays new messages. Open a second terminal to run tests or restart the service if it is safe to do so. Stop monitoring with Ctrl+C. Avoid making changes to production servers without understanding the impact or without recovery procedures.

5. Displaying Timestamps and Narrowing Search Ranges

Time ranges are usually more effective than reading the entire journal. For example:

journalctl --since "2026-10-15 14:00:00" --until "2026-10-15 15:00:00"

Adjust dates and times to match the incident and the machine’s time zone. To aid analysis, ISO format can be used for more consistent timestamps:

journalctl -u nginx -o short-iso --since "30 minutes ago"

If investigating an incident, record the exact time, service name, error message, and actions taken. This information helps compare events without copying entire logs.

6. Checking Disk Usage and Log Retention

The journal can grow over time. Check space usage with:

journalctl --disk-usage

If cleanup is needed, do so only after understanding retention policies and audit requirements. The following example asks systemd to remove archived journal files older than 14 days:

sudo journalctl --vacuum-time=14d

The vacuum command removes archived journal files; it is not a replacement for backup policies. Do not delete logs arbitrarily while investigating incidents or when the organization has specific retention obligations. Also ensure disk free space and storage policies are understood before changing configuration.

7. Why Don’t Previous Boot Logs Appear?

If journalctl -b -1 shows no data, the journal may not be configured for persistent storage. Check your distribution’s documentation and journald configuration before making changes. On systems that support persistent storage, the journal is typically stored in locations like /var/log/journal; actual settings may vary by distribution and administrator policy.

Do not create directories or change configuration blindly. Review existing configuration files, understand the impact of changes, then test whether logs remain available after a planned reboot.

Safe Practices When Reading Logs

  • Use sudo only when necessary and understand the access rights being granted.
  • Redact IP addresses, usernames, tokens, email addresses, and sensitive data before sharing log excerpts.
  • Do not jump to conclusions from a single message; check several lines before and after.
  • Preserve copies of required evidence according to security policies before cleanup.
  • Avoid pasting entire server logs to public services, as they may contain internal information.

Conclusion

journalctl helps Linux administrators investigate issues with service filters, priorities, time ranges, and live monitoring. Start from the incident time and relevant service unit, then expand the search if context is insufficient. By reading logs systematically and protecting sensitive data, troubleshooting becomes more focused without destroying evidence still needed.

Official references: journalctl documentation and systemd-journald configuration documentation.

Bagikan artikel ini

No comments yet

    Leave a comment

    Your email address will not be published. Required fields are marked *