A simple, zero-dependency crate for working with Systemd's
sd_journal
API's.
systemd_journal
provides an interface to the Systemd journal through
the Journal
type.
let jrn = systemd_journal::Journal::new();
systemd_journal::info!(jrn, "Hello, world!")?;
if let Err(err) = something::dangerous() {
systemd_journal::error!(jrn, "Oops: {}", err)?;
}
let mut reader = jrn.read()?;
if let Some(mut entry) = reader.next()? {
if let Some(message) = entry.get("MESSAGE")? {
println!("First journal entry: {:?}", String::from_utf8_lossy(message));
}
}
systemd_journal
can be used to set up the global logger for the
popular log crate.
fn main() {
systemd_journal::init_logger();
log::info!("Hello, world!");
}
Note: this requires enabling the "log"
feature in Cargo.toml
:
[dependencies.systemd-journal]
version = "0.1"
features = ["log"]
This project is licensed under the MIT license (see the LICENSE
file).