Skip to content

Beginner · Processes, services and logs · topic 17 of 57 · 30 min

Logs: journalctl, rsyslog and a persistent journal

Explanation

systemd-journald collects logs from the kernel and every service; journalctl reads them with filters like -u (unit), -p (priority), -b (boot) and --since. rsyslog also writes classic text logs such as /var/log/messages and /var/log/secure. To keep the journal across reboots, make it persistent.

Two log systems working together

On RHEL 9, systemd-journald receives log messages from the kernel, from services' output, and from programs using syslog. It stores them in a structured, indexed journal. rsyslog then reads from the journal and writes classic text files in /var/log. Both are useful: journalctl has powerful filters, and text files are easy to grep and to ship to a central log server.

FileWhat goes there
/var/log/messagesMost system messages
/var/log/secureLogins, sudo, SSH (security and authentication)
/var/log/cronScheduled jobs
/var/log/maillogMail server
/var/log/boot.logBoot-time service messages
/var/log/audit/audit.logAudit events, including SELinux denials (written by auditd)

Reading the journal

bash
$ journalctl -u sshd                   # one service
$ journalctl -u httpd --since "1 hour ago"
$ journalctl -p err -b                 # errors and worse, this boot
$ journalctl -f                        # follow, like tail -f
$ journalctl -n 20                     # last 20 lines
$ journalctl --since "2026-10-19 09:00" --until "2026-10-19 09:30"
$ journalctl _PID=1301                 # one process
$ journalctl -b -1                     # the previous boot (needs a persistent journal)
$ journalctl -o verbose -n 1           # every field of one entry

Priorities, from most to least serious: 0 emerg, 1 alert, 2 crit, 3 err, 4 warning, 5 notice, 6 info, 7 debug. -p err shows level 3 AND everything more serious (0 to 3). journalctl only shows everything to root and to members of the wheel or systemd-journal groups; others see only their own messages.

Making the journal persistent

By default the journal setting is Storage=auto: journald writes to /var/log/journal if that directory exists, otherwise only to /run/log/journal, which is in memory and lost at every reboot. Without a persistent journal you cannot read logs from before the last reboot, which is exactly when you need them after a crash. Check with ls /var/log/journal.

bash
# mkdir -p /var/log/journal
# systemctl restart systemd-journald
# journalctl --list-boots
IDX BOOT ID                          FIRST ENTRY                 LAST ENTRY
 -1 4b1c9e2d3f...                    Sun 2026-10-18 09:01:02 IST Sun 2026-10-18 23:59:10 IST
  0 9a7f6e5d4c...                    Mon 2026-10-19 09:00:58 IST Mon 2026-10-19 11:05:31 IST
Another way: set Storage=persistent in /etc/systemd/journald.conf (or a drop-in under /etc/systemd/journald.conf.d/), then restart systemd-journald.

Persistent journals are limited in size (by default up to 10% of the file system, with a cap). journalctl --disk-usage shows the size, and journalctl --vacuum-time=2weeks removes older entries. Classic text files are rotated by logrotate, configured in /etc/logrotate.conf and /etc/logrotate.d/.

Writing your own log lines

bash
$ logger -p user.notice "Backup finished: 12 GB"
$ journalctl -n 1
Oct 19 11:10:02 web01 asha[7720]: Backup finished: 12 GB
logger writes to the system log. Useful in scripts.

Common mistakes

  • Looking for yesterday's crash with journalctl -b -1 and getting "Specifying boot ID or boot offset has no effect, no persistent journal was found." Make the journal persistent before you need it.
  • Reading only /var/log/messages. Login problems are in /var/log/secure; SELinux denials are in /var/log/audit/audit.log.
  • Forgetting that time filters use the server's time zone. Check with timedatectl when comparing with users' reports.
Tip: When a service fails, the fastest first look is: systemctl status name, then journalctl -u name -b --no-pager | tail -50.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Logs: journalctl, rsyslog and a persistent journal · 1/7

journald → journal rsyslog → /var/log/*

journald collects logs from the kernel and every service. rsyslog writes classic text files.

Prefer a video by a teacher? Find free videos on “journalctl tutorial persistent journal rhel” on YouTube ↗

In real life: Why did the payments server reboot at 3 am?

A payments company in Pune finds a server rebooted overnight. Because the team had made the journal persistent on all servers, the engineer runs journalctl -b -1 -p warning and sees, at 02:58, kernel messages about memory errors followed by a watchdog reset. The hardware team replaces a memory module the same day. Without the persistent journal, those lines would have been lost.

bash
# journalctl -b -1 -p warning --no-pager | tail -3
Oct 19 02:58:11 pay03 kernel: EDAC MC0: 1 CE memory read error on CPU_SrcID#0_Ha#0_Chan#1_DIMM#0
Oct 19 02:58:40 pay03 kernel: mce: [Hardware Error]: Machine check events logged
Oct 19 02:59:02 pay03 kernel: watchdog: BUG: soft lockup - CPU#3 stuck for 23s!

Practice (0/3 done)

Task 1 · Question

Which command shows only the logs of the sshd service?

Task 2 · Code · Python

journalctl -p LEVEL shows messages at that priority and every MORE serious one. Write shown(message_level, filter_level) that returns True if a message is shown. Levels are names: emerg=0, alert=1, crit=2, err=3, warning=4, notice=5, info=6, debug=7. Example: shown("crit", "err") is True; shown("info", "warning") is False.

Task 3 · Practice

Make the journal persistent on your lab VM, reboot, and show the logs of the previous boot at priority err or worse.

Quick quiz

Question 1

1.Where are failed SSH logins recorded as text?

Question 2

2.journalctl -p warning shows which levels?

Question 3

3.Without /var/log/journal, where does journald keep logs?

Question 4

4.Which command writes a custom message to the system log?

Question 5

5.What does journalctl -b -1 show?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Where are failed SSH logins recorded as text?

Answer: /var/log/secure

Authentication events go to /var/log/secure.

journalctl -p warning shows which levels?

Answer: warning and all more serious levels (0 to 4)

-p shows that priority and higher (lower numbers).

Without /var/log/journal, where does journald keep logs?

Answer: /run/log/journal, lost at reboot

With Storage=auto and no /var/log/journal, logs stay in /run (RAM).

Which command writes a custom message to the system log?

Answer: logger

logger sends a message to the logging system.

What does journalctl -b -1 show?

Answer: The previous boot

-b -1 means one boot before the current one.

What does Persistent=true do in a timer?Related

Answer: Runs a missed job soon after boot if the machine was off at the scheduled time

It catches up on missed runs.

From One-time jobs with at, and systemd timers

What happens to files written inside a container (not in a volume) after podman rm?Related

Answer: They are deleted with the container

The container layer is removed.

From Persistent storage and containers as systemd services

Why use sudo instead of logging in as root?Related

Answer: Each admin action is tied to a named user and logged

Named users plus logging gives accountability and fewer mistakes.

From Linux security basics

Which command shows the logs of the service orders-api and keeps following new lines?Related

Answer: journalctl -u orders-api -f

journalctl -u selects the unit and -f follows new entries.

From Processes, signals and systemd services

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 1 more topic in “Processes, services and logs” before its exam: Tuning profiles with tuned, and time with chrony.
  2. Module 3 exam: Processes, services and logs · 14 questions · 25 min, without help. 6 topics of this module still to finish first.
  3. Then the next module, Software and networking. 57 topics left in the course before the final exam.

← Previous: Targets: the boot goal of the system