Logs & journald
Logs & journald
When a production system behaves unexpectedly — a service crashes, a request times out, a deployment silently fails — the first question is always: what does the log say? Logs are the primary diagnostic surface for every Linux system, and mastering them is non-negotiable for DevOps work. This lesson covers the two complementary logging systems you will encounter on every modern Linux host: systemd's journald and the traditional syslog stack, plus the canonical log file locations you need to know by heart.
How Linux Logging Works: Two Layers
On a modern system running systemd, logs flow through two parallel channels:
- journald (
/usr/lib/systemd/systemd-journald) — the systemd journal daemon. It captures everything that passes through the kernel ring buffer (dmesg), structured log entries from systemd units, and any output written tostdout/stderrby managed services. It stores logs in a binary, indexed format under/run/log/journal/(volatile) or/var/log/journal/(persistent). - rsyslog / syslog-ng — a traditional text-based syslog daemon that also runs in parallel on most distributions. journald can forward messages to it via a socket, producing the familiar plain-text files under
/var/log/.
Storage=persistent in /etc/systemd/journald.conf.
Enabling Persistent Journal Storage
The first thing to verify on any new server is whether the journal persists across reboots. Check by looking for /var/log/journal/:
journalctl: The Right Tool for Every Log Query
journalctl is the command-line interface to journald. At big-tech scale you will query it hundreds of times per week — learn its filters deeply.
-o json. journald stores rich metadata (PID, UID, command name, boot ID, monotonic timestamp) in every entry — fields that plain syslog text loses. Tools like Filebeat and Fluentd have native journald input plugins that exploit this structured data.
Visualising the Log Flow
Traditional Syslog: Key Log File Locations
Even in a world dominated by journald, plain-text log files remain essential — they are readable without tooling, trivially greppable, and consumed by countless legacy agents. Know these paths on every distribution:
| File / Path | What it contains |
|---|---|
/var/log/syslog (Debian/Ubuntu) |
General system messages; the catch-all log |
/var/log/messages (RHEL/CentOS) |
Same as syslog on Debian family |
/var/log/auth.log (Debian/Ubuntu) |
Authentication events: SSH logins, sudo, PAM |
/var/log/secure (RHEL/CentOS) |
Same as auth.log on Debian family |
/var/log/kern.log |
Kernel messages (OOM killer, hardware errors, network driver) |
/var/log/dmesg |
Boot-time kernel ring buffer snapshot |
/var/log/dpkg.log / yum.log |
Package install/remove history |
/var/log/nginx/, /var/log/apache2/ |
Web server access and error logs (app-specific) |
/var/log/audit/audit.log |
Linux Audit Framework events (SELinux, syscall auditing) |
Reading Logs Effectively: Patterns and Techniques
Raw log volume on a busy server can reach millions of lines per day. Effective log reading is about narrowing the search space fast:
Log Rotation with logrotate
Plain-text log files grow unbounded without rotation. logrotate is the standard daemon that compresses, renames, and purges old logs on a schedule. It is configured at /etc/logrotate.conf and per-service in /etc/logrotate.d/. A typical configuration for an application log looks like:
RateLimitIntervalSec=30s, RateLimitBurst=10000) and caps journal size at 10% of the filesystem. Always set explicit bounds in /etc/systemd/journald.conf: use SystemMaxUse=2G and SystemKeepFree=500M so the journal never starves your application of disk space. Run journalctl --disk-usage periodically in your monitoring runbooks.
Forwarding to Centralised Log Aggregation
Individual server logs are useful for quick triage, but at scale — dozens of hosts, microservices, Kubernetes pods — you must ship logs to a centralised platform. The standard production stack is:
- Filebeat or Fluentd/Fluent Bit — lightweight agents that tail files or read the journal directly (
journaldinput plugin) and forward to a backend. - Elasticsearch + Kibana (ELK/EFK) — the classic full-text search and visualisation stack. Expensive to operate at scale.
- Grafana Loki — the cloud-native, label-based log store. Much cheaper than Elasticsearch because it indexes only metadata labels, not the full text. Well-integrated with Prometheus and Grafana — the preferred choice for new greenfield deployments.
For the purposes of this tutorial series, the key skill is knowing what to look for and where, on the host itself. Aggregation pipelines are covered in the Observability track later in the course.
journalctl -u <service> -n 50 for the service's own output; (2) journalctl -k -b for kernel-level issues (OOM, hardware); (3) /var/log/auth.log or /var/log/secure if the failure involves permissions, PAM, or SSH. Most production bugs leave a trace in at least one of these three.