Skip to content

Commit

Permalink
chore: configure tracing only once
Browse files Browse the repository at this point in the history
commit-id:d56e92a1
  • Loading branch information
nadin-Starkware committed Dec 9, 2024
1 parent cbd8129 commit 35bcec4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/starknet_sequencer_infra/src/trace_util.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use std::sync::Once;

use tracing::metadata::LevelFilter;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO;
static INIT_TRACING: Once = Once::new();

pub fn configure_tracing() {
let fmt_layer = fmt::layer().compact().with_target(true);
let level_filter_layer =
EnvFilter::builder().with_default_directive(DEFAULT_LEVEL.into()).from_env_lossy();
INIT_TRACING.call_once(|| {
let fmt_layer = fmt::layer().compact().with_target(true);
let level_filter_layer =
EnvFilter::builder().with_default_directive(DEFAULT_LEVEL.into()).from_env_lossy();

// This sets a single subscriber to all of the threads. We may want to implement different
// subscriber for some threads and use set_global_default instead of init.
tracing_subscriber::registry().with(fmt_layer).with(level_filter_layer).init();
tracing_subscriber::registry().with(fmt_layer).with(level_filter_layer).init();
});
}

0 comments on commit 35bcec4

Please sign in to comment.