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:
parent
9fd901bc7f
commit
be9caa0b61
4 changed files with 581 additions and 0 deletions
51
crates/common/src/tracing_init.rs
Normal file
51
crates/common/src/tracing_init.rs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue