HosterQ

How to Use journalctl to View and Troubleshoot Linux Logs

25 Sep, 2026 HosterQ Editör Ekibi
Blue-toned conceptual illustration with Linux logo, server, code on laptop, and magnifying glass symbolizing log inspection.

journalctl reads messages collected by systemd-journald. It can answer which service failed, when a restart occurred and what the kernel reported around the same time. The useful starting point is a narrow question: a service name, an incident time and a boot session. Dumping every available entry usually hides that evidence.

This guide applies to Linux systems using systemd, including standard Ubuntu and Debian installations. Commands that only query logs are read-only; the retention section explicitly identifies commands that delete archived records. Available options depend on the installed systemd version, so check journalctl --version and man journalctl when an option is rejected.

Understand what the journal can and cannot show

systemctl status nginx.service reports the current unit state and a short log excerpt. journalctl -u nginx.service searches retained journal records associated with that unit. A service can be active now after failing earlier; its current status alone cannot establish what happened during an outage.

The journal can include kernel messages, service-manager events and application output that actually reaches journald. It does not automatically contain every application log file. Nginx access/error logs and PHP-FPM logs may be written to separate files, depending on configuration. An empty journal query therefore means no matching accessible journal entries, not proof that the application encountered no errors.

Access also matters. Try queries without elevation first, then use sudo if authorized system-wide records are required. Group permissions vary by distribution. Granting journal access can expose hostnames, account names and application data; it should not be treated as a harmless convenience. Prepare an appropriate account with the Ubuntu user and sudo access guide.

Read recent entries and follow a single service

journalctl -n 50 --no-pager
sudo journalctl -u nginx.service -n 100 --no-pager
sudo journalctl -u nginx.service -f

-n limits the number of recent entries. --no-pager writes output directly to the terminal, which is useful for a bounded query. -f continues displaying new entries; press Ctrl+C to stop following. Stopping this reader does not stop the service or journald.

A terminal window icon next to stacked document icons representing logs, with HosterQ branding in the bottom right corner.
Conceptual illustration: Commands for an initial log inspection.

A follow query may display recent existing entries before waiting for new messages. To investigate a reproducible request, note the time, start the service-specific query and repeat the request once. Record both the application symptom and any corresponding message. A nearby warning is a clue, not automatically the cause.

Use the exact installed unit name. List likely candidates with systemctl list-unit-files --type=service; PHP-FPM names commonly include a version, and SSH unit naming differs across distributions. The Ubuntu journalctl manual documents unit filtering, following and output controls.

Align the time window and boot session

sudo journalctl -u nginx.service --since "2026-09-20 14:00:00" --until "2026-09-20 14:15:00" -o short-iso --no-pager
sudo journalctl --list-boots
sudo journalctl -b -n 100 --no-pager
sudo journalctl -b -1 -p warning --no-pager

The dates above are examples; replace them with the actual incident interval. Without an explicit timezone, timestamps are interpreted using the machine’s local timezone. Check timedatectl before comparing them with a browser, monitoring system or another host. short-iso includes a timezone offset in displayed timestamps; --utc can make comparisons easier when used consistently.

-b selects the current boot, while -b -1 selects the previous available boot. Confirm which boots exist with --list-boots. A previous boot may be unavailable because storage was volatile, retention removed it or the account lacks permission. Rebooting a machine does not create a missing historical journal.

Relative times such as --since "30 minutes ago" are convenient during a live incident. Use absolute timestamps when preserving a reproducible investigation: the same relative query issued tomorrow examines a different interval.

Separate service, boot and kernel records

Use the service unit for application lifecycle events, the boot selector to avoid mixing restarts, and kernel records for host-level clues such as device or memory problems. A host event and an application message are different observations. Confirm the host and boot before combining them into one incident timeline.

Combine priority, unit and kernel filters carefully

sudo journalctl -u nginx.service -b --since "30 minutes ago" -p warning -o short-iso --no-pager
sudo journalctl -k -b --since "30 minutes ago" --no-pager
sudo journalctl -u nginx.service -u php8.3-fpm.service --since "30 minutes ago" --no-pager

-p warning includes warning and more severe priorities, not only warnings. This is useful for a first pass, but a service restart or application explanation may have an informational priority. Remove the priority filter before concluding that relevant records are absent. -k selects kernel messages; the example also states the boot explicitly.

The two-unit example compares related services; replace the PHP unit with the installed name. More advanced field filters are available, but inspect sudo journalctl -n 1 -o verbose before guessing field names. Different fields are normally combined with AND, repeated values for the same field with OR, and + separates alternative match groups. Unit options add their own matching logic, documented in the manual.

Choose an output format for the job

Use -o short-iso for readable timestamps, -o verbose to inspect journal fields, and -o json for structured processing. For example, sudo journalctl -u nginx.service -n 20 -o json --no-pager exports a bounded selection. Preserve the original fields when passing records to another tool; copying only the message can lose the host, unit or timestamp needed to interpret it.

Investigate a 502 response without confusing logs with causes

  1. Capture the failing URL, response time and timezone. Determine whether Nginx, another proxy or an upstream application produced the response.
  2. Read the proxy unit journal for that narrow interval and inspect the configured proxy error log. Do not assume the unit journal includes HTTP request details.
  3. Read the corresponding upstream service journal and its configured application log. Compare timestamps for a crash, restart, socket error or resource exhaustion.
  4. Inspect the relevant listener with sudo ss -ltnp for TCP or sudo ss -lxnp for Unix sockets. Compare it with the proxy’s configured upstream address.
  5. Change one verified cause, repeat the same request, and check whether the symptom and matching error both disappear.

For example, a proxy’s connection-refused message plus an absent upstream listener supports investigating the upstream service. A running listener does not prove it answers valid application requests. Restarting everything may temporarily clear the symptom while destroying useful timing evidence. The 502 troubleshooting guide expands the proxy/application checks.

Preserve evidence before changing journal retention

sudo journalctl --disk-usage
sudo journalctl -u nginx.service --since "2026-09-20 14:00:00" --until "2026-09-20 14:15:00" -o short-iso --no-pager

Before deleting history, save the incident interval to an access-controlled location according to your retention policy. Review it for tokens, personal data and internal addresses before sharing. Text output is convenient for reading; it is not a complete substitute for the original structured journal when forensic preservation is required.

These maintenance commands delete old archived journal files:

sudo journalctl --vacuum-time=14d
sudo journalctl --vacuum-size=500M

They are separate examples, not a mandatory cleanup sequence. Vacuum operations act on archived files; active journal files can keep total disk use above the requested size. --rotate rotates active files, so combining rotation with vacuum can make more history eligible for deletion. Only do that deliberately after preserving needed evidence. Never delete live journal files manually as a routine first response.

The journald.conf manual explains Storage= and size/retention settings. With Storage=auto, persistent storage depends on whether /var/log/journal exists; otherwise logs are volatile. Limits, rate limiting and application logging configuration should be reviewed before simply allocating more space.

Avoid common journalctl mistakes

Check permissions before interpreting an empty result. Remove a restrictive priority filter before ruling out an informational event. Check the configured application log destination before searching a longer journal interval. These checks answer different questions; increasing the number of returned lines cannot compensate for querying the wrong source.

Keep the incident workflow reproducible

Record the symptom and absolute time, identify the affected unit, collect its narrow journal interval, compare dependent-service and kernel evidence, then state one hypothesis. After a controlled change, repeat the same request and query. Save the before/after observations so another administrator can distinguish the tested explanation from a coincidental recovery.

Common questions and a repeatable handover

Why is the previous boot missing?

Check permissions, --list-boots, storage configuration and retention. Logs kept only under /run/log/journal do not survive a reboot. A later configuration change cannot recover entries that were never retained.

Does journalctl replace application or guest logs?

No. Applications may log elsewhere, and a virtualization host’s journal is distinct from the journals inside its guests. When working with Proxmox virtual machines, identify which machine owns the failing service before querying it.

What should an incident note include?

Record the host, boot ID, service, absolute time window with timezone, query used, observed messages and verification after the change. Distinguish an observed error from a hypothesis. This makes the next investigation reproducible without inventing certainty from incomplete logs.

Sources

Put this guide to work

Compare the number of websites, resource requirements and who will manage the server.

Cloud server and VPS plans

Compare CPU, memory and storage options for your applications.

Dedicated server hosting

Compare physical servers by processor, memory, storage and network requirements.

Talk to sales

Leave a Reply

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