Skip to content

Commit

Permalink
Auto merge of #78548 - camelid:driver-tty, r=oli-obk
Browse files Browse the repository at this point in the history
driver: Only output ANSI logging if connected to a terminal

Fixes #78435.

See #78435 for more.

Cc `@RalfJung` `@oli-obk`
  • Loading branch information
bors committed Nov 24, 2020
2 parents 7445993 + 173a7db commit 1c389ff
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions compiler/rustc_driver/src/lib.rs
Expand Up @@ -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)
Expand All @@ -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),
)
})
})
Expand Down

0 comments on commit 1c389ff

Please sign in to comment.