-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |