mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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`
This commit is contained in:
commit
1c389ffeff
@ -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),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user