Notes on Journald
Journalctl is a tool that I have used a few times in the past, but I never fully understood how it works. After renting a VPS for this website, I started to become interested in analysing some system logs, and I decided to take a deeper look at how logging on systemd works.
As usual, the Arch Wiki contains a lot of relevant information.
You can read the man pages with man systemd-journald
Some concepts
- systemd - Systemd is a software suite that provides a system and service manager for most linux distributions.
- journald - A service that stores system logs
- journactl - A tool to view journald logs
Configuring journald
You can configure journald by changing the /etc/systemd/journald.conf. A useful configuration you can specify here is if you want to persist you logs on disc, how long and until how much space.
[Journal]
Storage=persistent
SystemMaxUse=100M
MaxRetentionSec=3monthTwo useful values for Storage are:
- persistent: Persistent the logs on disc (you can specify the retention parameters like in the example above)
- volatile: Only write logs to ram.
When you set it to persistent, logs will be saved to /var/log/journal. However, they are saved in a binary format, so we need a special tool to read these logs.
Using journalctl
journalctl is the tool to allow you view logs.
With the following commands, we can see the latest logs on our system
> journalctl -n 5
Okt 18 13:02:40 v1111111111111111111 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=5a:a6:2f:b7:b6:f4:bc:1f:fe:37:1b:a3:08:00 SRC=111.111.111.111 DST=111.111.111.111 LEN=44 TOS=0x00 PREC=0x00 TTL=249 ID=10384 PROTO=TCP SPT=54114 DPT=682 WINDOW>
Okt 18 13:03:02 v1111111111111111111 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=5a:a6:2f:b7:b6:f4:bc:1f:fe:37:1b:a3:08:00 SRC=111.111.111.111 DST=111.111.111.111 LEN=40 TOS=0x00 PREC=0x00 TTL=248 ID=32581 PROTO=TCP SPT=44857 DPT=8080 WINDO>
Okt 18 13:03:12 v1111111111111111111 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=5a:a6:2f:b7:b6:f4:bc:1f:fe:37:1b:a3:08:00 SRC=111.111.111.111 DST=111.111.111.111 LEN=40 TOS=0x00 PREC=0x00 TTL=243 ID=54321 PROTO=TCP SPT=36553 DPT=4117 WIN>
Okt 18 13:03:25 v1111111111111111111 sshd-session[1236]: Unable to negotiate with 111.111.11.111 port 00000: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1>
Okt 18 13:03:38 v1111111111111111111 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=5a:a6:2f:b7:b6:f4:bc:1f:fe:37:1b:a3:08:00 SRC=111.111.111.111 DST=111.111.111.111 LEN=40 TOS=0x00 PREC=0x00 TTL=243 ID=54321 PROTO=TCP SPT=52612 DPT=7443 WIN>The log messages follow the format.
Okt 18 13:02:40 v1111111111111111111 kernel: [UFW BLOCK] IN=eth0 ...
└── timestamp ──┘ └───── hostname ─────┘ └─ tag ─┘ └──── message body ────┘A few interesting things already: We got a few attempts blocked by ufw, and also a denied attempt to ssh into my server. Also we can not that there is no standard for the mesasges themselves.
We can use journald to fetch logs from a particular service, like sshd
> journalctl -n 5 -u ssh
Okt 18 13:10:10 v1111111111111111111 sshd-session[1113]: Connection closed by invalid user admin 1.11.111.11 port 11111 [preauth]
Okt 18 13:10:51 v1111111111111111111 sshd-session[1115]: Connection closed by authenticating user root 111.11.111.111 port 11111 [preauth]
Okt 18 13:12:31 v1111111111111111111 sshd-session[1117]: Connection closed by authenticating user root 111.11.111.111 port 11111 [preauth]
Okt 18 13:14:10 v1111111111111111111 sshd-session[1110]: Connection closed by authenticating user root 111.11.111.111 port 11111 [preauth]
Okt 18 13:15:47 v1111111111111111111 sshd-session[1115]: Connection closed by authenticating user root 111.11.111.111 port 11111 [preauth]-u here means systemd unit, that is defined on /etc/systemd/system . We can also filter by tag using -t, but tag is defined by the logging program on the syslog standard.
If we want too read messages from UFW, we can use grep
journalctl -k --grep '\[UFW ' -n 5More journactl commands
Journald can tell you how much logs you have stored.
> journalctl --disk-usage
Archived and active journals take up 91M in the file system.You can also see the boots of your computer
> journalctl --list-boots
IDX BOOT ID FIRST ENTRY LAST ENTRY
-2 11111111111111111111111111111111 Sat 2026-10-10 18:18:23 CEST Sun 2026-10-18 12:05:11 CEST
-1 11111111111111111111111111111111 Sun 2026-10-18 12:05:28 CEST Mon 2026-10-19 10:51:06 CEST
0 11111111111111111111111111111111 Mon 2026-10-19 12:14:25 CEST Fri 2026-10-23 17:05:54 CESTAnd finally, if you want to see your earliest log, you can run
❯ journalctl | head -n 1
Okt 14 18:18:23 v1111111111111111111 kernel: Linux version 6.11.111+deb13-amd64 (debian-kernel@lists.debian.org) (x86_64-linux-gnu-gcc-14 (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44) #1 SMP PREEMPT_DYNAMIC Debian 6.11.111-1 (2026-09-28)Writing to journald
Any systemd service has their logs to stdout and stderr collected in journald by default.
Routing nginx logs
You would expect that your nginx logs would show up on journald when you run nginx as a systemd service. They do not (by default). The problem is that nginx writes logs to text files in /var/log/nginx and not to stdout.
The official docs do not specify a way to make nginx log to stdout and stderr.
We can however route nginx logs to journald by adding the following to our nginx configuration:
access_log stderr;
error_log syslog:server=unix:/dev/log;This takes advantage that nginx can write to syslog
Afterwards, we can see the nginx access log with
> journalctl -u nginx