crates/common: add bootstrap, tracing_init, and nix_probe modules

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ifbc17b000a4fb4a10e05ac9405582a366a6a6964
This commit is contained in:
raf 2026-02-02 01:22:40 +03:00
commit be9caa0b61
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 581 additions and 0 deletions

View file

@ -0,0 +1,51 @@
//! Tracing initialization helper for all FC daemons.
use tracing_subscriber::EnvFilter;
use tracing_subscriber::fmt;
use crate::config::TracingConfig;
/// Initialize the global tracing subscriber based on configuration.
///
/// Respects `RUST_LOG` environment variable as an override. If `RUST_LOG` is
/// not set, falls back to the configured level.
pub fn init_tracing(config: &TracingConfig) {
let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&config.level));
match config.format.as_str() {
"json" => {
let builder = fmt()
.json()
.with_target(config.show_targets)
.with_env_filter(env_filter);
if config.show_timestamps {
builder.init();
} else {
builder.without_time().init();
}
}
"full" => {
let builder = fmt()
.with_target(config.show_targets)
.with_env_filter(env_filter);
if config.show_timestamps {
builder.init();
} else {
builder.without_time().init();
}
}
_ => {
// "compact" or any other value
let builder = fmt()
.compact()
.with_target(config.show_targets)
.with_env_filter(env_filter);
if config.show_timestamps {
builder.init();
} else {
builder.without_time().init();
}
}
}
}