systemd-journal-logger-memfd-syscall
A pure Rust log logger for the systemd journal (fork supporting older glibc versions).
About this fork
This crate is a fork of
systemd-journal-logger. The
only reason for the existence of this fork is that the maintainer of
systemd-journal-logger
is not willing to support glibc versions older than 2.27.
The
only modification included in this fork
is calling the memfd_create
syscall (which is available starting with the Linux kernel 3.17) instead of the
memfd_create()
libc function, which in glibc it is available starting with
glibc 2.27, while Rust supports glibc >= 2.17.
This fork will try to merge all the changes done upstream and release versions in the same way as upstream.
Usage
$ cargo add systemd-journal-logger-memfd-syscall
Then initialize the logger at the start of main
:
use ;
use JournalLog;
new.unwrap.install.unwrap;
set_max_level;
info!;
warn!;
error!;
You can also add additional fields to every log message, such as the version of your executable:
use ;
use JournalLog;
new
.unwrap
.with_extra_fields
.with_syslog_identifier
.install.unwrap;
set_max_level;
info!;
These extra fields appear in the output of journalctl --output=verbose
or in any of the JSON output formats of journalctl
.
See systemd_service.rs for a simple example of logging in a systemd service which automatically falls back to a different logger if not started through systemd.
Related projects
- rust-systemd provides a logger implementation based on the
libsystemd
C library. - slog-journald provides an slog logger for the systemd journal, also based on the
libsystemd
C library. - tracing-journald provides a tracing backend for the systemd journal, in a pure Rust implementation.
Both loggers use mostly the same fields and priorities as this implementation.
License
Either MIT or Apache 2.0, at your option.