-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
19 additions
and
10 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
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
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,24 @@ | ||
use tokio::sync::OnceCell; | ||
use tracing::metadata::LevelFilter; | ||
use tracing_subscriber::prelude::*; | ||
use tracing_subscriber::{fmt, EnvFilter}; | ||
|
||
const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO; | ||
// Define a OnceCell to ensure the configuration is initialized only once | ||
static TRACING_INITIALIZED: OnceCell<()> = OnceCell::const_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(); | ||
pub async fn configure_tracing() { | ||
TRACING_INITIALIZED | ||
.get_or_init(|| async { | ||
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(); | ||
// 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::info!("Tracing has been successfully initialized."); | ||
}) | ||
.await; | ||
} |
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