Linux Logs and journalctl: Where to Look First
Your website stops answering. systemctl status nginx says failed, but the lines below it do not say why. The full story is in the logs. This lesson shows where Linux keeps them, how to read them with journalctl, how to find the one line that explains a failure, and how to stop logs filling the disk.
Where Linux logs live
A log is a record of time-stamped messages that programs write about what they do and what goes wrong. Linux keeps logs in two kinds of place, and most servers have both.
The first is plain text files in /var/log, the folder for changing data (lesson 5). The system-wide files are written by rsyslog, a service that sorts system messages into files by topic. Applications such as nginx, a web server, keep their own files there too.
The second is the journal, kept by systemd-journald, the logging service that comes with systemd (lesson 12). It collects kernel messages, system messages and whatever each service prints to stdout and stderr (lesson 8). It saves them in indexed files under /var/log/journal, so you read them with journalctl, not cat. If that folder does not exist, it uses /run/log/journal, which is lost at every reboot.
The table lists the usual places. Notice that the same kind of message has a different file name on each family, while journalctl works the same everywhere.
Some files, such as auth.log, need sudo to read. Without rsyslog, as on some newer systems, the system files are missing and the journal is the only system log.
journalctl basics
On its own, journalctl shows every entry you may read, oldest first, a screen at a time in the less pager: Space moves on and q quits. These options narrow it down, and you can combine them:
-u nginx: only entries from one unit, here nginx.service.-n 50: only the newest 50 entries;-nalone means 10.-f: follow, printing new entries as they arrive, liketail -ffor a file, until you press Ctrl+C.--since '1 hour ago': only the past hour;--untilsets an end.-p err: only priority err and more serious, explained below.-b: only entries since the machine last started.--no-pager: print straight to the terminal, without less.
For the failing web server, this asks for nginx's newest 20 entries, with sudo, because only root and a few groups, such as adm or systemd-journal, may read system entries:
sudo journalctl -u nginx -n 20 --no-pager
Between systemd's own lines saying the start failed, nginx explains why (trimmed; times, host name and PID are illustrative):
Dec 02 10:20:16 web1 nginx[2301]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Dec 02 10:20:18 web1 nginx[2301]: nginx: [emerg] still could not bind()
nginx could not take port 80, because another program already listens there; lesson 12 found such a program with ss. nginx tries five times, half a second apart, then gives up. If you see -- No entries -- instead, check the unit name, which systemctl status prints on its first line.
Reading a log line
journalctl's default format prints one line per entry, laid out like a classic syslog file. The diagram labels the four parts of the last line above.
The timestamp uses the machine's local time and has no year. The host is the machine's name. Then come the program, with its process ID in brackets, and the message.
Every entry also carries a priority, or severity: how serious it is, on eight levels from 0, emerg (the system is unusable), to 7, debug (detail for developers). -p err shows levels 0 to 3; on a terminal, journalctl colours them red and warnings yellow.
The priority comes from the program, not from the words in its message. Text that a service simply prints is stored as info, level 6, unless the program marks it otherwise. So nginx's [emerg] lines are info to the journal, and -p err skips them, as the diagram shows. Use -p for an overview, and search the text too.
Searching for one error
A busy service writes thousands of lines, so you search them with grep (lesson 9). The flowchart shows the order to look in. Notice that each step reads further back, so you stop once one line explains the failure.
For step 4, pipe journalctl into grep. -i ignores case, so this finds fail, failed and Failed in the past hour:
sudo journalctl -u nginx --since '1 hour ago' --no-pager | grep -i fail
You should see the bind() to 0.0.0.0:80 failed line from above, plus systemd's lines saying the start failed. No output means no line has the word: try another, such as error, or drop --since. journalctl can also search itself with -g fail.
For step 5, nginx's error log is a text file, so tail takes its last 200 lines and grep keeps the serious ones:
sudo tail -n 200 /var/log/nginx/error.log | grep emerg
The same problem appears in nginx's own layout: the date with the year, the level in brackets, then the process ID and a thread number (illustrative values):
2026/12/02 10:20:16 [emerg] 2301#2301: bind() to 0.0.0.0:80 failed (98: Address already in use)
2026/12/02 10:20:18 [emerg] 2301#2301: still could not bind()
No such file or directory means nginx is not installed or logs elsewhere; its configuration in /etc/nginx names the file.
Retention: keeping logs from filling the disk
Logs grow every day, and a full disk stops services from writing. Linux limits both kinds of log.
For text files, logrotate runs daily from a systemd timer or cron. Rotation renames the current file, for example syslog to syslog.1, starts a fresh one, compresses older copies into .gz files and deletes the oldest. Packages add rules in /etc/logrotate.d/. A rule for an app, saved as /etc/logrotate.d/myapp, looks like this:
/var/log/myapp/*.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
}
It rotates daily and keeps seven old copies. compress shrinks them, but delaycompress waits one round, so the newest copy, such as app.log.1, stays plain text. missingok and notifempty skip a missing or empty file. sudo logrotate -d /etc/logrotate.d/myapp prints what it would do and changes nothing.
The journal limits itself. By default it uses at most 10% of its filesystem, capped at 4 GB, keeps 15% free, and deletes its oldest archived files, the full ones it has closed, to stay within that. To see its size, run this with sudo, so it counts every file:
sudo journalctl --disk-usage
Archived and active journals take up 56.0M in the file system.
The size is illustrative. To set a limit, put SystemMaxUse=500M under [Journal] in /etc/systemd/journald.conf, then run sudo systemctl restart systemd-journald, which is safe. sudo journalctl --vacuum-size=200M deletes old archived files at once, for good. The journalctl manual lists every option.
Check yourself
systemctl status nginx says failed without saying why. What next, and why does it help?
sudo journalctl -u nginx -n 100. status shows only the last 10 lines; the journal keeps earlier entries, where the first error usually sits.
Your app printed ERROR: database unreachable, yet journalctl -u myapp -p err shows nothing. Why?
The journal stores a service's printed output as info unless the program marks its priority, so -p err filters it out. Search the text: journalctl -u myapp | grep -i error.
After a reboot, the journal has no entries from before it. What is the likely cause?
/var/log/journal does not exist, so journald kept its files under /run/log/journal, which is emptied at every boot. Creating the folder makes the journal persistent.