Evaluate systemd logs using journalctl
Analysis Options
Before we had systemd, if your system didn't recognise an external drive such as a USB stick, your only choice was to examine the output of dmesg
using the command tail -n 10
. This would show the last ten lines of output, hopefully displaying when the stick was connected. Journalctl has a built-in function for this. Use journalctl -n <value>
to display the last x number of lines.
System admins also used to use the command tail -f
to keep track of logfiles. On operating systems using systemd, you can now achieve the same thing by running journalctl -f
. By way of example, run the command journalctl -u apache2 -f
. Use Ctrl+C to interrupt the continuous output.
Output to other formats
If you want to analyze a journal in a different way, you can output data to other formats. See Listing 7 for an example of how to save all syslog Error levels as a simple text file. For other file types, use the -o
or --output
to specify the format. The default output is short
and matches the syslog output.
Listing 7
Saving All Syslog Error Levels
The option -o verbose
provides a more comprehensive output with all metadata and fields. Use -o cat
as an alternative to short
. Use the option -o short-monotonic
for a more precise time-stamp. This will allow a more reliable comparison of outputs from different sources.
For further analysis of journal data using web tools, you can use the output options -o json
or -o json-pretty
. If you simply want to send the journal over the network in binary format, use -o export
.
Safety and security
As efficient as the binary files are, if the logs do become corrupted, there's currently no way to repair them. However, their contents will usually be preserved. You can use your built-in Linux commands such as strings
and grep
to filter only uncorrupted data, as shown in Listing 8.
Listing 8
Filtering Only Uncorrupted Data
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
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.