Skip to content

Commit 208f973

Browse files
committed
Make rustdoc share the logger initialization routine with rustc.
1 parent 64296ec commit 208f973

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/librustc_driver/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1224,11 +1224,18 @@ pub fn install_ice_hook() {
12241224
}
12251225

12261226
/// This allows tools to enable rust logging without having to magically match rustc's
1227-
/// log crate version
1227+
/// log crate version.
12281228
pub fn init_rustc_env_logger() {
1229+
init_env_logger("RUSTC_LOG")
1230+
}
1231+
1232+
/// This allows tools to enable rust logging without having to magically match rustc's
1233+
/// log crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var
1234+
/// other than `RUSTC_LOG`.
1235+
pub fn init_env_logger(env: &str) {
12291236
let builder = tracing_subscriber::FmtSubscriber::builder();
12301237

1231-
let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env("RUSTC_LOG"));
1238+
let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env(env));
12321239

12331240
builder.init()
12341241
}

src/librustdoc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(never_type)]
1515
#![recursion_limit = "256"]
1616

17-
extern crate env_logger;
1817
#[macro_use]
1918
extern crate lazy_static;
2019
extern crate rustc_ast;
@@ -90,7 +89,8 @@ pub fn main() {
9089
};
9190
rustc_driver::set_sigpipe_handler();
9291
rustc_driver::install_ice_hook();
93-
env_logger::init_from_env("RUSTDOC_LOG");
92+
rustc_driver::init_env_logger("RUSTDOC_LOG");
93+
9494
let res = std::thread::Builder::new()
9595
.stack_size(thread_stack_size)
9696
.spawn(move || get_args().map(|args| main_args(&args)).unwrap_or(1))

0 commit comments

Comments
 (0)