systemd-journal-logger-memfd-syscall

Crates.iosystemd-journal-logger-memfd-syscall
lib.rssystemd-journal-logger-memfd-syscall
version2.0.1
sourcesrc
created_at2023-10-18 10:30:17.313982
updated_at2023-10-20 06:59:12.71085
descriptionSystemd journal logger for the log facade (fork supporting older glibc versions) DEPRECATED
homepage
repositoryhttps://github.com/daniestevez/systemd-journal-logger.rs
max_upload_size
id1006584
size85,307
Daniel Estévez (daniestevez)

documentation

https://docs.rs/systemd-journal-logger-memfd-syscall

README

systemd-journal-logger-memfd-syscall (deprecated)

A pure Rust log logger for the systemd journal (fork supporting older glibc versions).

About this fork

Update: Since version 2.1.0, systemd-journal-logger is now using rustix. Rustix uses syscalls instead of calling the libc functions, so systemd-journal-logger works again with old glibc versions and there is no need to maintain this fork. This fork is now marked as deprecated. systemd-journal-logger >= 2.1 should be used instead.

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 log::{info, warn, error, LevelFilter};
use systemd_journal_logger_memfd_syscall::JournalLog;

JournalLog::new().unwrap().install().unwrap();
log::set_max_level(LevelFilter::Info);

info!("hello log");
warn!("warning");
error!("oops");

You can also add additional fields to every log message, such as the version of your executable:

use log::{info, warn, error, LevelFilter};
use systemd_journal_logger_memfd_syscall::JournalLog;

JournalLog::new()
    .unwrap()
    .with_extra_fields(vec![("VERSION", env!("CARGO_PKG_VERSION"))])
    .with_syslog_identifier("foo".to_string())
    .install().unwrap();
log::set_max_level(LevelFilter::Info);

info!("this message has an extra VERSION field in the journal");

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

Both loggers use mostly the same fields and priorities as this implementation.

License

Either MIT or Apache 2.0, at your option.

Commit count: 104

cargo fmt