ArchWiki / Systemd/Journal
ArchWiki / Systemd/Journal
es:Systemd (Español)/Journal fr:Systemd (Français)/Journal hu:Systemd (Magyar)/Journal it:Systemd (Italiano)/Journal ja:Systemd/ジャーナル pt:Systemd (Português)/Journal ru:Systemd (Русский)/Journal zh-hans:Systemd/Journal systemd has its own logging system called the journal; running a separate logging daemon is not required.
systemd journal classifies messages by Priority level and Facility. Logging classification corresponds to classic Syslog protocol (RFC 5424).
Accessing the journal
The journal is read using journalctl(1), typically in one of two ways: inspecting previous logs, or watching new entries as they are logged.
For the former, the -e/--pager-end option is typically useful; the latter is enabled by the -f/--follow option.
Both of these options imply some form of -n/--lines, unless that option is also specified somewhere else on the command line.
Filtering output
journalctl allows its output to be filtered in many ways. This is useful to make logs easier to sift through, because journalctl can struggle displaying logs in real-time if there are too many of them...
Non-option arguments enable filtering by journal fields (e.g. _PID1, see systemd.journal-fields(7)), executable path, or kernel device, as described in journalctl(1).
See Lennart Poettering's blog post for some examples.
A full list of additional options, and the short form of the following, is available at journalctl(1), but here are the most common ones:
Show all messages matching
PATTERN:# journalctl --grepPATTERNThis should be preferred over
journalctl grep, as it avoids journalctl performing more work only for it to be discarded.Include explanations of log messages from the message catalog where available:
# journalctl --catalogNote that this feature should not be used when attaching logs to bug reports and support threads, as to limit extraneous output. You can list all known catalog entries by running
journalctl --list-catalog.Show all messages from a given time onwards (systemd.time(7)):
# journalctl --since"2012-10-30 18:17:16"# journalctl --since "20 min ago"Show all messages from the current boot:
# journalctl --bootShow all messages by a specific identifier:
# journalctl --identifier sudoShow all messages by a specific unit: (the
.servicesuffix can be omitted)# journalctl --unit man-db.serviceNote that user services require the use of
--user-unitinstead:$ journalctl --user-unit dbusShow only error, critical and alert priority messages:
# journalctl --priority err..alertYou can use numeric log level too, like
journalctl -p 3..1. If single number/log level is used,journalctl -p 3, then all higher priority log levels are also included (i.e. 0 to 3 in this case).If the journal directory (by default located under
/var/log/journal) contains a large amount of log data thenjournalctlcan take several minutes to filter output. It can be sped up significantly by using--fileoption to forcejournalctlto look only into most recent journal:# journalctl --file /var/log/journal/*/system.journal -f
Specify a different journal to view
There may be a need to check the logs of another system that is dead in the water, like booting from a live system to recover a production system. In such case, one can mount the disk in e.g. /mnt, and specify the journal path via -D/--directory, like so:
# journalctl -D /mnt/var/log/journal -eExamining journal without journalctl
While the journal is stored in a binary format, the content of stored messages is not modified.
This means it is viewable with strings, for example for recovery in an environment which does not have systemd installed, e.g.:
$ strings /mnt/arch/var/log/journal/af4967d77fba44c6b093d0e9862f6ddd/system.journal grep -i messagePriority level
A syslog severity code (in systemd called priority) is used to mark the importance of a message RFC 5424 6.2.1.These rules are recommendations, and the priority level of a given error is at the application developer's discretion. It is always possible that the error will be at a higher or lower level than expected.
Facility
A syslog facility code is used to specify the type of program that is logging the message RFC 5424 6.2.1.Useful facilities to watch: 0, 1, 3, 4, 9, 10, 15.
Journal storage
In Arch Linux, the directory /var/log/journal/ is a part of the systemd package. Since the default mode for the journal is Storagepersistent, the journal will write to /var/log/journal/, and the directory will be created if it is not present. If the mode is manually configured to Storageauto, systemd will instead write its logs to /run/log/journal/ in a non-persistent way.
Journal size limit
The default size limit for persistent journals (the default mode) corresponds to 10% of the size of the underlying file system, but has a soft-cap at 4 GiB. For example, with /var/log/journal/ located on a 20 GiB partition, journal data may take up to 2 GiB. On a 50 GiB partition, it would at max. at 4 GiB. To confirm the current limits on your system, review systemd-journald unit logs:
# journalctl -b -u systemd-journaldThe maximum size of the persistent journal can be controlled by uncommenting and changing the following:
SystemMaxUse=50M/etc/systemd/journald.confIf SystemMaxUse is set to a large amount, it may still be limited by the default SystemKeepFree parameter, which is set to 15 percent of the underlying filesystem. The journal daemon will respect both parameters, and use the smaller of the two.
It is also possible to use the drop-in snippets configuration override mechanism rather than editing the global configuration file. In this case, place the overrides under the [Journal] header:
[Journal]
SystemMaxUse=50M/etc/systemd/journald.conf.d/00-journal-size.confRestart the systemd-journald.service after changing this setting to apply the new limit.
See journald.conf(5) for more info.
Clean journal files manually
Journal files can be globally removed from /var/log/journal/ using e.g. rm, or can be trimmed according to various criteria using journalctl. For example:
Remove archived journal files until the disk space they use falls below 100M:
# journalctl --vacuum-size100MMake all journal files contain no data older than 2 weeks.
# journalctl --vacuum-time2weeks
Journal files must have been rotated out and made inactive before they can be trimmed by vacuum commands. Rotation of journal files can be done by running journalctl --rotate. The --rotate argument can also be provided alongside one or more vacuum criteria arguments to perform rotation and then trim files in a single command.
See journalctl(1) for more info.
Tips and tricks
Per unit size limit by a journal namespace
Edit the unit file for the service you wish to configure (for example sshd) and add LogNamespacessh in the [Service] section.
Then create /etc/systemd/journald@ssh.conf by copying /etc/systemd/journald.conf. After that, edit journald@ssh.conf and adjust SystemMaxUse to your liking.
Restarting the service should automatically start the new journal service systemd-journald@ssh.service. The logs from the namespaced service can be viewed with journalctl --namespace ssh.
See systemd-journald.service(8) for details about journal namespaces.
Journald in conjunction with syslog
Compatibility with a classic, non-journald aware syslog implementation can be provided by letting systemd forward all messages via the socket /run/systemd/journal/syslog. To make the syslog daemon work with the journal, it has to bind to this socket instead of /dev/log (official announcement).
The default journald.conf for forwarding to the socket is ForwardToSyslogno to avoid system overhead, because rsyslog or syslog-ng pull the messages from the journal by itself.
See Syslog-ng#Overview and Syslog-ng#syslog-ng and systemd journal, or rsyslog respectively, for details on configuration.
Forward journald to /dev/tty12
Create a drop-in directory /etc/systemd/journald.conf.d and create a fw-tty12.conf file in it:
[Journal]
ForwardToConsole=yes
TTYPath=/dev/tty12/etc/systemd/journald.conf.d/fw-tty12.confThen restart systemd-journald.service.
* By design, this does not forward kernel ring log messages. * This does not have to be TTY 12 specifically, however that TTY must not be controlled by another process. In particular, see getty#Add additional virtual consoles if you wish to use TTY 1 to 6.
Journal access as user
By default, a regular user only has access to their own per-user journal. To grant read access for the system journal as a regular user, you can add that user to the systemd-journal user group. Members of the adm and wheel groups are also given read access.
See journalctl(1) and Users and groups#User groups for more information.
Desktop notifications
Desktop notifications can help you quickly notice error messages, improving awareness compared to manually checking logs or not noticing them at all.
The journalctl-desktop-notification package provides an automatic desktop notification for each error message logged by any process. For more details and configuration options, visit the GitLab project page.
Hiding the hostname
By default, journalctl(1) shows the hostname of the machine which generated the logs, which is pertinent if you are viewing the logs of multiple machines at once (possibly on different terminals).
But, in other cases, the -W/--no-hostname option can help make lines shorter.
Wrap journal lines instead of truncating them
By default, journalctl truncates lines longer than screen width, but in some cases, it may be better to enable wrapping instead of truncating.
This can be controlled by the SYSTEMD_LESS environment variable, which contains options passed to less (the default pager) and defaults to FRSXMK (see less(1) and journalctl(1) for details).
By omitting the S option, the output will be wrapped instead of truncated. For example, start journalctl as follows:
$ SYSTEMD_LESSFRXMK journalctlTo set this behaviour as default, add this as an environment variable.
Printing kernel messages only
journalctl can be used as a dmesg(1) alternative:
# journalctl --dmesg