manta_shared/common/log_ops.rs
1//! Tracing-subscriber initialisation shared by both binaries.
2
3use tracing_subscriber::EnvFilter;
4
5/// Configure the global tracing subscriber and bridge `log::` calls into it.
6///
7/// `log_level` is an `EnvFilter` directive string, e.g. `"info"`, `"debug"`,
8/// or `"manta=debug,hyper=warn"`. Falls back to `"error"` on parse failure.
9///
10/// `with_timestamps` controls whether each emitted line is prefixed with
11/// the local time. The long-running server enables this so operators can
12/// correlate events across requests; the interactive CLI disables it to
13/// keep terminal output uncluttered.
14pub fn configure(log_level: String, with_timestamps: bool) {
15 let filter =
16 EnvFilter::try_new(&log_level).unwrap_or_else(|_| EnvFilter::new("error"));
17
18 let builder = tracing_subscriber::fmt()
19 .with_env_filter(filter)
20 .with_target(false);
21
22 if with_timestamps {
23 builder.init();
24 } else {
25 builder.without_time().init();
26 }
27}