Skip to content

Commit

Permalink
Make rustdoc share the logger initialization routine with rustc.
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jul 31, 2020
1 parent 64296ec commit 208f973
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/librustc_driver/lib.rs
Expand Up @@ -1224,11 +1224,18 @@ pub fn install_ice_hook() {
}

/// This allows tools to enable rust logging without having to magically match rustc's
/// log crate version
/// log crate version.
pub fn init_rustc_env_logger() {
init_env_logger("RUSTC_LOG")
}

/// This allows tools to enable rust logging without having to magically match rustc's
/// 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) {
let builder = tracing_subscriber::FmtSubscriber::builder();

let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env("RUSTC_LOG"));
let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env(env));

builder.init()
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/lib.rs
Expand Up @@ -14,7 +14,6 @@
#![feature(never_type)]
#![recursion_limit = "256"]

extern crate env_logger;
#[macro_use]
extern crate lazy_static;
extern crate rustc_ast;
Expand Down Expand Up @@ -90,7 +89,8 @@ pub fn main() {
};
rustc_driver::set_sigpipe_handler();
rustc_driver::install_ice_hook();
env_logger::init_from_env("RUSTDOC_LOG");
rustc_driver::init_env_logger("RUSTDOC_LOG");

let res = std::thread::Builder::new()
.stack_size(thread_stack_size)
.spawn(move || get_args().map(|args| main_args(&args)).unwrap_or(1))
Expand Down

0 comments on commit 208f973

Please sign in to comment.