diff options
| author | bors <bors@rust-lang.org> | 2020-11-24 20:58:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-24 20:58:20 +0000 |
| commit | 1c389ffeff814726dec325f0f2b0c99107df2673 (patch) | |
| tree | fe14d296d3d3877bb4829d990be9428b58ff2d99 | |
| parent | 74459930a951db7a68b3ecd86f3b796339e59fe5 (diff) | |
| parent | 173a7dbace4f3d9921dd1c66830c847aff9ba23b (diff) | |
| download | rust-1c389ffeff814726dec325f0f2b0c99107df2673.tar.gz rust-1c389ffeff814726dec325f0f2b0c99107df2673.zip | |
Auto merge of #78548 - camelid:driver-tty, r=oli-obk
driver: Only output ANSI logging if connected to a terminal Fixes #78435. See #78435 for more. Cc `@RalfJung` `@oli-obk`
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index e49e456792b..e87d8b7ab45 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -1284,11 +1284,30 @@ pub fn init_env_logger(env: &str) { Ok(s) if s.is_empty() => return, Ok(_) => {} } + let color_logs = match std::env::var(String::from(env) + "_COLOR") { + Ok(value) => match value.as_ref() { + "always" => true, + "never" => false, + "auto" => stdout_isatty(), + _ => early_error( + ErrorOutputType::default(), + &format!( + "invalid log color value '{}': expected one of always, never, or auto", + value + ), + ), + }, + Err(std::env::VarError::NotPresent) => stdout_isatty(), + Err(std::env::VarError::NotUnicode(_value)) => early_error( + ErrorOutputType::default(), + "non-Unicode log color value: expected one of always, never, or auto", + ), + }; let filter = tracing_subscriber::EnvFilter::from_env(env); let layer = tracing_tree::HierarchicalLayer::default() .with_writer(io::stderr) .with_indent_lines(true) - .with_ansi(true) + .with_ansi(color_logs) .with_targets(true) .with_wraparound(10) .with_verbose_exit(true) @@ -1314,7 +1333,7 @@ pub fn main() -> ! { arg.into_string().unwrap_or_else(|arg| { early_error( ErrorOutputType::default(), - &format!("Argument {} is not valid Unicode: {:?}", i, arg), + &format!("argument {} is not valid Unicode: {:?}", i, arg), ) }) }) |
