Skip to content

Commit 9cbdfa7

Browse files
authored
Use EnvFilter config to set default tracing level (#196)
1 parent 1b4d345 commit 9cbdfa7

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

examples/axum/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ use tracing::{info_span, Instrument};
66
use turmoil::{net, Builder};
77

88
fn main() {
9-
if std::env::var("RUST_LOG").is_err() {
10-
std::env::set_var("RUST_LOG", "info");
11-
}
12-
13-
tracing_subscriber::fmt::init();
9+
tracing_subscriber::fmt()
10+
.with_env_filter(
11+
tracing_subscriber::EnvFilter::builder()
12+
.with_default_directive(tracing::level_filters::LevelFilter::INFO.into())
13+
.from_env_lossy(),
14+
)
15+
.init();
1416

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

examples/grpc/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ fn main() {
6666
/// An example of how to configure a tracing subscriber that will log logical
6767
/// elapsed time since the simulation started using `turmoil::sim_elapsed()`.
6868
fn configure_tracing() {
69-
if std::env::var("RUST_LOG").is_err() {
70-
std::env::set_var("RUST_LOG", "info");
71-
}
72-
7369
tracing::subscriber::set_global_default(
7470
tracing_subscriber::fmt()
75-
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
71+
.with_env_filter(
72+
tracing_subscriber::EnvFilter::builder()
73+
.with_default_directive(tracing::level_filters::LevelFilter::INFO.into())
74+
.from_env_lossy(),
75+
)
7676
.with_timer(SimElapsedTime)
7777
.finish(),
7878
)

0 commit comments

Comments
 (0)