Don't register a tracing dispatcher if no tracing env var was set.

This commit is contained in:
Oliver Scherer 2020-07-28 15:49:04 +02:00
parent 358e21ee78
commit 401033c684
1 changed files with 6 additions and 0 deletions

View File

@ -1233,6 +1233,12 @@ pub fn init_rustc_env_logger() {
/// log crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var
/// other than `RUSTC_LOG`.
pub fn init_env_logger(env: &str) {
// Don't register a dispatcher if there's no filter to print anything
match std::env::var(env) {
Err(_) => return,
Ok(s) if s.is_empty() => return,
Ok(_) => {}
}
let builder = tracing_subscriber::FmtSubscriber::builder();
let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env(env));