Skip to content

Commit

Permalink
Fix RUST_LOG env overrides
Browse files Browse the repository at this point in the history
Adapted workaround from tokio-rs/tracing#1466
  • Loading branch information
XA21X committed Aug 12, 2021
1 parent e1b601c commit 8023027
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion shotover-proxy/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::net::SocketAddr;

use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -118,7 +119,18 @@ impl TracingState {

let builder = tracing_subscriber::fmt()
.with_writer(non_blocking)
.with_env_filter(log_level)
.with_env_filter({
// Override directives using RUST_LOG environment variable. Workaround for tokio-rs/tracing#512.
let overrides = env::var(EnvFilter::DEFAULT_ENV).ok();
let directives = [Some(log_level), overrides.as_deref()]
.iter()
.flat_map(Option::as_deref)
.map(str::trim)
.filter(|s| !s.is_empty())
.collect::<Vec<_>>()
.join(",");
EnvFilter::new(directives)
})
.with_filter_reloading();
let handle = builder.reload_handle();

Expand Down

0 comments on commit 8023027

Please sign in to comment.