use tracing_subscriber::prelude::*;
pub fn initialize_tracing() {
let journald_layer = if rustix::process::getuid().is_root() {
tracing_journald::layer()
.ok()
.map(|layer| layer.with_filter(tracing_subscriber::filter::LevelFilter::INFO))
} else {
None
};
let format = tracing_subscriber::fmt::format()
.without_time()
.with_target(false)
.compact();
let fmt_layer = tracing_subscriber::fmt::layer()
.event_format(format)
.with_writer(std::io::stderr)
.with_filter(tracing_subscriber::EnvFilter::from_default_env());
match journald_layer {
Some(journald) => {
tracing_subscriber::registry()
.with(fmt_layer)
.with(journald)
.init();
}
None => {
tracing_subscriber::registry().with(fmt_layer).init();
}
}
}