Crates.io | systemd-journal-logger |
lib.rs | systemd-journal-logger |
version | 2.2.0 |
source | src |
created_at | 2021-05-28 19:41:39.453618 |
updated_at | 2024-10-17 17:23:30.971254 |
description | Systemd journal logger for the log facade. |
homepage | |
repository | https://github.com/swsnr/systemd-journal-logger.rs |
max_upload_size | |
id | 403297 |
size | 83,038 |
A pure Rust log logger for the systemd journal.
$ cargo add systemd-journal-logger
Then initialize the logger at the start of main
:
use log::{info, warn, error, LevelFilter};
use systemd_journal_logger::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::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.
libsystemd
C library.libsystemd
C library.Both loggers use mostly the same fields and priorities as this implementation.
The MSRV used in this repo is best effort only and may be bumped at any time, even in patch releases.
Either MIT or Apache 2.0, at your option.