bootc_internal_utils/
tracing_util.rs1use tracing_subscriber::prelude::*;
4
5pub fn initialize_tracing() {
7 let journald_layer = if rustix::process::getuid().is_root() {
10 tracing_journald::layer()
11 .ok()
12 .map(|layer| layer.with_filter(tracing_subscriber::filter::LevelFilter::INFO))
13 } else {
14 None
15 };
16
17 let format = tracing_subscriber::fmt::format()
20 .without_time()
21 .with_target(false)
22 .compact();
23
24 let fmt_layer = tracing_subscriber::fmt::layer()
25 .event_format(format)
26 .with_writer(std::io::stderr)
27 .with_filter(tracing_subscriber::EnvFilter::from_default_env());
28
29 match journald_layer {
31 Some(journald) => {
32 tracing_subscriber::registry()
33 .with(fmt_layer)
34 .with(journald)
35 .init();
36 }
37 None => {
38 tracing_subscriber::registry().with(fmt_layer).init();
39 }
40 }
41}