Skip to content

Commit

Permalink
Use EnvFilter config to set default tracing level (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Dec 27, 2024
1 parent 1b4d345 commit 9cbdfa7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions examples/axum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use tracing::{info_span, Instrument};
use turmoil::{net, Builder};

fn main() {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}

tracing_subscriber::fmt::init();
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::builder()
.with_default_directive(tracing::level_filters::LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();

let addr = (IpAddr::from(Ipv4Addr::UNSPECIFIED), 9999);

Expand Down
10 changes: 5 additions & 5 deletions examples/grpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ fn main() {
/// An example of how to configure a tracing subscriber that will log logical
/// elapsed time since the simulation started using `turmoil::sim_elapsed()`.
fn configure_tracing() {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}

tracing::subscriber::set_global_default(
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_env_filter(
tracing_subscriber::EnvFilter::builder()
.with_default_directive(tracing::level_filters::LevelFilter::INFO.into())
.from_env_lossy(),
)
.with_timer(SimElapsedTime)
.finish(),
)
Expand Down

0 comments on commit 9cbdfa7

Please sign in to comment.