Introduction
On Linux systems that use systemd, the journal
daemon, systemd-journald, collects messages from the kernel, from services and from
syslog, and stores them in binary .journal files. They are kept under
/var/log/journal/ and the machine’s ID, as system.journal and
one file per user, with older files renamed and kept as archives. Without that folder
the journal is kept only in memory, under /run/log/journal/.
Each entry is a set of fields, not just a line of text: the message, its priority, the
process, user, unit and boot it came from, and the time. The journalctl
command reads the files and can filter on any field.
Structure
All values are little-endian. The file starts with a
header beginning with the
signature LPKSHHRH. It holds flags for compatible and incompatible features,
the file’s state, IDs for the file, the machine and the boot, the sizes and positions of
the hash tables, and counts of objects and entries.
Everything after the header is an object,
aligned to 8 bytes. Every object starts with
a type, flags and its size. Data objects hold one FIELD=value pair, such
as MESSAGE=… or _PID=…, stored once however many entries use
it, and possibly compressed with XZ, LZ4 or Zstandard. Field objects name each field.
Entry objects hold one log entry: its sequence number, times and boot ID, and references
to its data objects. Hash tables find data and field objects by value, entry arrays list
entries in order, and tag objects carry the seals of Forward Secure Sealing.
0HeaderLPKSHHRH, flags, state, IDs, table positions, countsvaries…Objects data, field, entry, hash table, entry array and tag objectsrepeated
Not described
These pages follow systemd’s published journal file format document. The explorer has no journal viewer, so a dropped file shows as bytes.
Known, not yet covered
- Reference: the journal export format, a separate text format, is not covered.
- Reference: the rules a writer and reader follow beyond the layout, such as rotation, and the sealing fields.
- Viewer: there is no journal plugin: the header, objects and hash tables are not read.
Unknown
- Reference: whether the hash table offsets in the header point at items; the document does not say.
Links
Software
- journalctl and systemd-journald – the journal reader and the daemon that writes the files, part of systemd (Linux)
- lnav – log file viewer that can read the journal through journalctl (Linux, macOS)
Developers
- sd-journal – the API in libsystemd for reading and writing the journal (C)
- python-systemd – systemd bindings that include a journal reader (Python)
Reference
- Journal File Format – the systemd project’s description of the format