Skip to content

Commit e7f0485

Browse files
committed
rustc_driver: Enable the WARN log level by default
This commit changes the `tracing_subscriber` initialization in `rustc_driver` so that the `WARN` verbosity level is enabled by default when the `RUSTC_LOG` env variable is empty. If the `RUSTC_LOG` env variable is set, the filter string in the environment variable is honored, instead. Fixes #76824 Closes #89623 cc @eddyb, @oli-obk
1 parent 680ff86 commit e7f0485

File tree

1 file changed

+11
-8
lines changed
  • compiler/rustc_driver/src

1 file changed

+11
-8
lines changed

compiler/rustc_driver/src/lib.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1253,12 +1253,16 @@ pub fn init_rustc_env_logger() {
12531253
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var
12541254
/// other than `RUSTC_LOG`.
12551255
pub fn init_env_logger(env: &str) {
1256-
// Don't register a dispatcher if there's no filter to print anything
1257-
match std::env::var(env) {
1258-
Err(_) => return,
1259-
Ok(s) if s.is_empty() => return,
1260-
Ok(_) => {}
1261-
}
1256+
use tracing_subscriber::{
1257+
filter::{self, EnvFilter, LevelFilter},
1258+
layer::SubscriberExt,
1259+
};
1260+
1261+
let filter = match std::env::var(env) {
1262+
Ok(env) => EnvFilter::from_env(env),
1263+
_ => EnvFilter::default().add_directive(filter::Directive::from(LevelFilter: WARN)),
1264+
};
1265+
12621266
let color_logs = match std::env::var(String::from(env) + "_COLOR") {
12631267
Ok(value) => match value.as_ref() {
12641268
"always" => true,
@@ -1278,7 +1282,7 @@ pub fn init_env_logger(env: &str) {
12781282
"non-Unicode log color value: expected one of always, never, or auto",
12791283
),
12801284
};
1281-
let filter = tracing_subscriber::EnvFilter::from_env(env);
1285+
12821286
let layer = tracing_tree::HierarchicalLayer::default()
12831287
.with_writer(io::stderr)
12841288
.with_indent_lines(true)
@@ -1288,7 +1292,6 @@ pub fn init_env_logger(env: &str) {
12881292
#[cfg(parallel_compiler)]
12891293
let layer = layer.with_thread_ids(true).with_thread_names(true);
12901294

1291-
use tracing_subscriber::layer::SubscriberExt;
12921295
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
12931296
tracing::subscriber::set_global_default(subscriber).unwrap();
12941297
}

0 commit comments

Comments
 (0)