< Systemd

systemd/Journal

systemd has its own logging system called the journal; running a separate logging daemon is not required. To read the log, use journalctl(1).

In Arch Linux, the directory /var/log/journal/ is a part of the systemd package, and the journal (when Storage= is set to auto in /etc/systemd/journald.conf) will write to /var/log/journal/. If that directory is deleted, systemd will not recreate it automatically and instead will write its logs to /run/systemd/journal in a nonpersistent way. However, the directory will be recreated if Storage=persistent is added to journald.conf and systemd-journald.service is restarted (or the system is rebooted).

Systemd journal classifies messages by Priority level and Facility. Logging classification corresponds to classic Syslog protocol (RFC 5424).

Priority level

A syslog severity code (in systemd called priority) is used to mark the importance of a message RFC 5424 6.2.1.

ValueSeverityKeywordDescriptionExamples
0EmergencyemergSystem is unusableSevere Kernel BUG, systemd dumped core.
This level should not be used by applications.
1AlertalertShould be corrected immediatelyVital subsystem goes out of work. Data loss.
.
2CriticalcritCritical conditionsCrashes, coredumps. Like familiar flash:

Failure in the system primary application, like X11.
3ErrorerrError conditionsNon-fatal error reported:
,
,
libvirtd[1720]: internal error: Failed to initialize a valid firewall backend
4WarningwarningMay indicate that an error will occur if action is not takenA non-root file system has only 1GB free.
org.freedesktop. Notifications[1860]: (process:5999): Gtk-WARNING **: Locale not supported by C library. Using the fallback 'C' locale
5NoticenoticeEvents that are unusual, but not error conditions,
6InformationalinfoNormal operational messages that require no action
7DebugdebugMessages which may need to be enabled first, only useful for debugging

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.

Facility codeKeywordDescriptionInfo
0kernKernel messages
1userUser-level messages
2mailMail systemArchaic POSIX still supported and sometimes used (for more )
3daemonSystem daemonsAll daemons, including systemd and its subsystems
4authSecurity/authorization messagesAlso watch for different facility 10
5syslogMessages generated internally by syslogdFor syslogd implementations (not used by systemd, see facility 3)
6lprLine printer subsystem (archaic subsystem)
7newsNetwork news subsystem (archaic subsystem)
8uucpUUCP subsystem (archaic subsystem)
9Clock daemonsystemd-timesyncd
10authprivSecurity/authorization messagesAlso watch for different facility 4
11ftpFTP daemon
12-NTP subsystem
13-Log audit
14-Log alert
15cronScheduling daemon
16local0Local use 0 (local0)
17local1Local use 1 (local1)
18local2Local use 2 (local2)
19local3Local use 3 (local3)
20local4Local use 4 (local4)
21local5Local use 5 (local5)
22local6Local use 6 (local6)
23local7Local use 7 (local7)

Useful facilities to watch: 0, 1, 3, 4, 9, 10, 15.

Filtering output

journalctl allows for the filtering of output by specific fields. If there are many messages to display, or if the filtering of large time spans has to be done, the output of this command can be extensively delayed.

Examples:

  • Show all messages matching :
  • Show all messages from this boot: However, often one is interested in messages not from the current, but from the previous boot (e.g. if an unrecoverable system crash happened). This is possible through optional offset parameter of the -b flag: shows messages from the current boot, journalctl -b -1 from the previous boot, from the second previous and so on – you can see the list of boots with their numbers by using . See journalctl(1) for a full description; the semantics are more powerful than indicated here.
  • Include explanations of log messages from the message catalog where available: Note 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 .
  • Show all messages from date (and optional time):
  • Show all messages since 20 minutes ago:
  • Follow new messages:
  • Show all messages by a specific executable:
  • Show all messages by a specific process:
    # journalctl _PID=1
  • Show all messages by a specific unit:
  • Show all messages from user services by a specific unit:
  • Show kernel ring buffer:
  • Show only error, critical and alert priority messages: You can use numeric log level too, like journalctl -p 3..1. If single number/log level is used, , then all higher priority log levels are also included (i.e. 0 to 3 in this case).
  • Show auth.log equivalent by filtering on syslog facility:
  • If the journal directory (by default located under ) contains a large amount of log data then can take several minutes to filter output. It can be sped up significantly by using --file option to force to look only into most recent journal:

See journalctl(1), , or Lennart Poettering's blog post for details.

Journal size limit

If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the underlying file system but capped 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 max at 4 GiB. To confirm current limits on your system review unit logs:

# journalctl -b -u systemd-journald

The maximum size of the persistent journal can be controlled by uncommenting and changing the following:

/etc/systemd/journald.conf
SystemMaxUse=50M

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 header:

Restart the systemd-journald.service after changing this setting to apply the new limit.

See for more info.

Per unit size limit by a journal namespace

Edit the unit file for the service you wish to configure (for example sshd) and add in the [Service] section.

Then create by copying /etc/systemd/journald.conf. After that, edit and adjust to your liking.

Restarting the service should automatically start the new journal service . The logs from the namespaced service can be viewed with .

See for details about journal namespaces.

Clean journal files manually

Journal files can be globally removed from /var/log/journal/ using e.g. , or can be trimmed according to various criteria using . For example:

  • Remove archived journal files until the disk space they use falls below 100M:
    # journalctl --vacuum-size=100M
  • Make all journal files contain no data older than 2 weeks.

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 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.

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 . To make the syslog daemon work with the journal, it has to bind to this socket instead of (official announcement).

The default journald.conf for forwarding to the socket is 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 and create a file in it:

Then restart systemd-journald.service.

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. , and specify the journal path via -D/, like so:

# journalctl -D /mnt/var/log/journal -e

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 user group. Members of the and wheel groups are also given read access.

See and Users and groups#User groups for more information.

gollark: Maybe you need a few examples to prompt it with.
gollark: Humans are missing lots of senses other animals have. IR/UV vision, good smell, magnetic compass support, the weird electric field detector in I think sharks, polarised light sensing from cuttlefish, working low light vision (via actually having a sane eye design), probably others.
gollark: I read a convincing reddit post about how weightlifting was excellent for health etc. in 2019 or so, then proceeded to entirely ignore it forever.
gollark: Gene guns are no longer trendy, cool people use something something CRISPR.
gollark: Human DNA only holds about 20GB. There isn't enough room.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.