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

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • QJournalctl

    QJournalctl is a convenient GUI tool that will help you track down log data in the systemd journal.

  • Command Line: Systemd

    Wondering what all the fuss is about systemd? We explain the basic concepts and capabilities of the new system management suite – coming soon to a distro near you.

  • Systemd GUIs

    Graphical frontends make it easier to take full advantage of the Systemd process manager. We examine some leading tools for the KDE environment.

  • Tutorials – Systemd

    Take control of the services running on your Linux machine

  • Professor Knopper's Lab – Removing systemd

    The systemd service manager has been widely adopted by many Linux distros, so why would you want to remove it? The professor reveals why and how.

comments powered by Disqus
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.

Learn More

News