diff options
| author | Yuki Omoto <yukeomoto@gmail.com> | 2023-01-12 00:17:48 +0900 | 
|---|---|---|
| committer | Yuki Omoto <yukeomoto@gmail.com> | 2023-01-12 00:17:48 +0900 | 
| commit | 4e2a3567bc14ad7b7e9d28f31fc1a468976ebc81 (patch) | |
| tree | b1e06330b9cfad3f160b0acc8df47b7cf1602a99 /compiler/rustc_driver/src/lib.rs | |
| parent | 1e4f90061cc4bc566f99ab21b1f101182b10cf0c (diff) | |
| download | rust-4e2a3567bc14ad7b7e9d28f31fc1a468976ebc81.tar.gz rust-4e2a3567bc14ad7b7e9d28f31fc1a468976ebc81.zip | |
Add log-backtrace option to show backtraces along with logging
Diffstat (limited to 'compiler/rustc_driver/src/lib.rs')
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 14 | 
1 files changed, 12 insertions, 2 deletions
| diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index fcb73c64356..dcce56ba763 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -231,6 +231,10 @@ fn run_compiler( registry: diagnostics_registry(), }; + if !tracing::dispatcher::has_been_set() { + init_rustc_env_logger_with_backtrace_option(&config.opts.unstable_opts.log_backtrace); + } + match make_input(config.opts.error_format, &matches.free) { Err(reported) => return Err(reported), Ok(Some((input, input_file_path))) => { @@ -1299,7 +1303,14 @@ pub fn install_ice_hook() { /// This allows tools to enable rust logging without having to magically match rustc's /// tracing crate version. pub fn init_rustc_env_logger() { - if let Err(error) = rustc_log::init_rustc_env_logger() { + init_rustc_env_logger_with_backtrace_option(&None); +} + +/// This allows tools to enable rust logging without having to magically match rustc's +/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to +/// choose a target module you wish to show backtraces along with its logging. +pub fn init_rustc_env_logger_with_backtrace_option(backtrace_target: &Option<String>) { + if let Err(error) = rustc_log::init_rustc_env_logger_with_backtrace_option(backtrace_target) { early_error(ErrorOutputType::default(), &error.to_string()); } } @@ -1365,7 +1376,6 @@ mod signal_handler { pub fn main() -> ! { let start_time = Instant::now(); let start_rss = get_resident_set_size(); - init_rustc_env_logger(); signal_handler::install(); let mut callbacks = TimePassesCallbacks::default(); install_ice_hook(); | 
