journalctl (systemd logs)
The systemd journal is systemd’s own logging system. It is equivalent to the syslog in the init system. It collects and stored kernel logging data, system log messages, standard output, and errors for various systemd services.
A Linux machine with systemd writes the logs to /var/log/journal directory.journalctl allows to filter the logs based on time, service, severity and other things.
The config file is: /etc/systemd/journald.conf
The journald.conf file shows the default values. So even if there is a # in front of the entries, it means those are the default settings being used. If you want to change anything, you remove the # from that line.With the command journalctl you can see the logs. But is becomes interesting to use filters.
with -r (reverse) you see the latest logs first
journalctl -rWith -n (number) you can set the number of lines form the log
journalctl -n 25Like with tail -f, the -f (follow) show the logs in real time. (ctrl+c to quit)
Show only kernel messages with -k
journalctl -kYou can filter on a specific process.
example logs generated by ssh
journalctl -u sshFilter logs by time
journalctl --since "2024-01-01"
journalctl --since=yesterday --until=now
journalctl --since "2024-01-01 01:01:00" --until "2024-02-02"you can change the timestamps to UTS with --utc
journalctl --utcFilter logs based on UID, GID and PID
The journal logs can also be filtered on User ID (UID), Group ID (GID) and Process ID (PID).
journalctl _PID=1234Show only errors in logs with journalctl
journalctl -p 3 -xbPriority Code
- -p 3 : filter logs for priority 3 (which is error)
- -x : provides additional information on the log (if available)
- b : since last boot (which is the current session)
0 emerg
1 alert
2 crit
3 err
4 warning
5 notice
6 info
7 debug
You might get a surprise when you see the output:
journalctl --disk-usageThis show the diskspace used by the logs.
You can rotate the logs, this will mark the currently active journal logs as archive and create fresh new logs.
sudo journalctl --rotateTo free up space you have several options:
Clear journal log older than x days
sudo journalctl --vacuum-time=7dRestrict logs to a certain size
sudo journalctl --vacuum-size=100MRestrict number of archive log files
sudo journalctl --vacuum-files=3