#logging #systemd #journal

systemd-journal-logger

Systemd journal logger for the log facade

9 releases (5 breaking)

0.7.0 Dec 23, 2022
0.5.1 Oct 15, 2022
0.5.0 Jan 28, 2022
0.4.1 Nov 20, 2021
0.3.0 Jun 7, 2021

#67 in Debugging

Download history 191/week @ 2022-11-28 420/week @ 2022-12-05 308/week @ 2022-12-12 212/week @ 2022-12-19 97/week @ 2022-12-26 211/week @ 2023-01-02 504/week @ 2023-01-09 528/week @ 2023-01-16 482/week @ 2023-01-23 675/week @ 2023-01-30 617/week @ 2023-02-06 633/week @ 2023-02-13 352/week @ 2023-02-20 622/week @ 2023-02-27 592/week @ 2023-03-06 672/week @ 2023-03-13

2,278 downloads per month
Used in 4 crates

MIT/Apache

21KB
222 lines

systemd-journal-logger

A pure Rust log logger for the systemd journal.

This logger used libsystemd and has no dependency on the libsystemd C library.

Usage

[dependencies]
log = "^0.4"
systemd-journal-logger = "0.7.0"

Then initialize the logger at the start of main:

use log::{info, LevelFilter};

fn main() {
    systemd_journal_logger::init();
    log::set_max_level(LevelFilter::Info);

    info!("Hello systemd journal");
}

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

use log::{info, LevelFilter};

fn main() {
    let version = env!("CARGO_PKG_VERSION");
    systemd_journal_logger::init_with_extra_fields(vec![("VERSION", version)]).unwrap();
    log::set_max_level(LevelFilter::Info);

    info!("Hello systemd 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.

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

License

Either MIT or Apache 2.0, at your option.

Dependencies

~4.5MB
~100K SLoC