diff options
author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-02-07 14:24:35 +0000 |
---|---|---|
committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-02-07 16:33:03 +0000 |
commit | f95b553eb4b6a2a0bf45e48c0cc5e9f635ba1e0c (patch) | |
tree | 742e4e289d4e01bf3aefc24077a13aa922b9af27 /compiler/rustc_log | |
parent | dffea43fc1102bdfe16d88ed412c23d4f0f08d9d (diff) | |
download | rust-f95b553eb4b6a2a0bf45e48c0cc5e9f635ba1e0c.tar.gz |
Replace a command line flag with an env var to allow tools to initialize the tracing loggers at their own discretion
Diffstat (limited to 'compiler/rustc_log')
-rw-r--r-- | compiler/rustc_log/src/lib.rs | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index fc1cabd2de9..019fdc30dce 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -54,25 +54,12 @@ use tracing_subscriber::fmt::{ use tracing_subscriber::layer::SubscriberExt; pub fn init_rustc_env_logger() -> Result<(), Error> { - init_rustc_env_logger_with_backtrace_option(&None) -} - -pub fn init_rustc_env_logger_with_backtrace_option( - backtrace_target: &Option<String>, -) -> Result<(), Error> { - init_env_logger_with_backtrace_option("RUSTC_LOG", backtrace_target) + init_env_logger("RUSTC_LOG") } /// In contrast to `init_rustc_env_logger` this allows you to choose an env var /// other than `RUSTC_LOG`. pub fn init_env_logger(env: &str) -> Result<(), Error> { - init_env_logger_with_backtrace_option(env, &None) -} - -pub fn init_env_logger_with_backtrace_option( - env: &str, - backtrace_target: &Option<String>, -) -> Result<(), Error> { let filter = match env::var(env) { Ok(env) => EnvFilter::new(env), _ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)), @@ -106,8 +93,8 @@ pub fn init_env_logger_with_backtrace_option( let layer = layer.with_thread_ids(true).with_thread_names(true); let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer); - match backtrace_target { - Some(str) => { + match env::var(format!("{env}_BACKTRACE")) { + Ok(str) => { let fmt_layer = tracing_subscriber::fmt::layer() .with_writer(io::stderr) .without_time() @@ -115,7 +102,7 @@ pub fn init_env_logger_with_backtrace_option( let subscriber = subscriber.with(fmt_layer); tracing::subscriber::set_global_default(subscriber).unwrap(); } - None => { + Err(_) => { tracing::subscriber::set_global_default(subscriber).unwrap(); } }; |