Skip to content

driver: Only output ANSI logging if connected to a terminal #78548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 24, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,22 @@ 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(),
_ => panic!("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)) => {
panic!("non-unicode log color value: expected one of always, never, or auto")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use early_error I think.

}
};
let filter = tracing_subscriber::EnvFilter::from_env(env);
let layer = tracing_tree::HierarchicalLayer::default()
.with_indent_lines(true)
.with_ansi(true)
.with_ansi(color_logs)
.with_targets(true)
.with_thread_ids(true)
.with_thread_names(true)
Expand Down