Skip to content

Commit

Permalink
Adding RUST_LOG support to tracing
Browse files Browse the repository at this point in the history
Also default level has been upped to info
  • Loading branch information
ecton committed Nov 10, 2023
1 parent 89dcffd commit 0c3206a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
66 changes: 66 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ kempt = "0.2.1"
intentional = "0.1.0"
tracing = "0.1.40"

tracing-subscriber = { version = "0.3", optional = true }
tracing-subscriber = { version = "0.3", optional = true, features = [
"env-filter",
] }
palette = "0.7.3"


Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,24 @@ fn initialize_tracing() {
#[cfg(feature = "tracing-output")]
{
use tracing::Level;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

#[cfg(debug_assertions)]
const MAX_LEVEL: Level = Level::DEBUG;
const MAX_LEVEL: Level = Level::INFO;
#[cfg(not(debug_assertions))]
const MAX_LEVEL: Level = Level::ERROR;

let _result = tracing_subscriber::fmt::fmt()
.with_max_level(MAX_LEVEL)
.finish()
.with(
EnvFilter::builder()
.with_default_directive(LevelFilter::from_level(MAX_LEVEL).into())
.from_env_lossy(),
)
.try_init();
}
}

0 comments on commit 0c3206a

Please sign in to comment.