Evaluate systemd logs using Journalctl

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

$ sudo journalctl -b -p err --no-pager >journal.txt

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

$ sudo strings /var/log/journal/ID | grep -i search string

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

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

US / Canada

Get it on Google Play

UK / Australia

Related content