Evaluate systemd logs using journalctl
Finely Filtered
The journal is the systemd component responsible for viewing and managing logfiles.
The systemd service journald creates very comprehensive logs, which allow you to analyze data in a variety of ways. Once you get used to the convenience this affords, you won't even miss the old-style logfiles.
Better structured
The journald daemon collects messages from the kernel, initrd, any running services and other available sources and collects them into one place. This results in a massive amount of data compared to the logfiles you're traditionally used to such as /var/log/messages or /var/log/syslog. You'll also find a huge amount of metadata is included, which can significantly improve your results when searching the journal.
This also results in a larger amount of data which is tricky to store in traditional text files. This is why the journald daemon stores this information in binary files. You can read this data, using the command journalctl
. If necessary, you can also convert the binary files to other formats for further analysis.
A little off the top
The huge amount of data being logged results in large files. While your system previously managed to trim these down using the Logrotate tool to compress and archive logfiles, the systemd journal allows you to set limits when files are changed.
Take a look at your own systemd [1] configuration file. For non-Debian based Linux distros, this is usually found in /etc/systemd/journald.conf
. You may also find it in /etc/systemd/journald.conf
. Look for the values SystemMaxUse
and SystemKeepFree
. The first of these determines how much space the journal files contain. The second value specifies how much free space to allocate (Figure 1).
Both values will determine the absolute limit on journal file sizes and available space. If you don't enter any values, the default amount of space permitted for journal files is 10 percent of your filesystem. The minimum amount of free space is 15 percent by default. The program caps both values at 4 GB for each.
Given the size of hard drives nowadays, it's perfectly feasible to set SystemMaxUse
to somewhere between 50 MB to 1 GB. In any case, the default values for the journal are sufficient for everyday use. Feel free to change the SystemMaxFileSize
to limit the size of individual files if you think it's necessary, however.
When setting size limits, use the values K
,G
and T
for kilobytes, gigabytes and terabytes respectively. If you want to alter the default values in journald.conf
, make sure to uncomment each line by removing the #
at the start, then restart the journald daemon.
Persistent or volatile?
Take a look at the line reading Storage=. While most Linux distributions are configured to store logs continuously, your logs will only be saved to var/log/journal
if you set this to Storage=persistent
. If you don't want to save the logs, change this to Storage=volatile
instead. Doing this means your logs will be stored in /run/log/journal
but will be deleted by the daemon once your active session ends.
For more options for controlling the journal size, pull up the man page for journald.conf
. If you want to reduce the journal size while it's running, you have two choices. Your first choice is to use the following command to reduce journal size, for instance to 100 MB. While running as root, enter:
# journalctl --vacuum-size=100M
The program will delete the oldest entries until the journal reaches the desired size (in this case 100 MB). Your second option is to remove all entries before a certain time:
# journalctl --vacuum-time=1month
The above command discards all messages older than one month (Figure 2), irrespective of how large or small this would make the logfile.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4
-
Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpm-ostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.
-
Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.