Skip to content

Commit f8159fe

Browse files
committed
feat(log): make console_logger() accept RUSTUP_TERM_COLOR and NO_COLOR
1 parent ce51d7d commit f8159fe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/cli/log.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ where
6565
S: Subscriber + for<'span> LookupSpan<'span>,
6666
{
6767
let maybe_rust_log_directives = process.var_os("RUST_LOG").clone();
68-
let has_ansi = process.stderr().is_a_tty();
68+
let has_ansi = {
69+
let env_override = process.var("RUSTUP_TERM_COLOR").map(|it| it.to_lowercase());
70+
match env_override.as_deref() {
71+
Ok("always") => true,
72+
Ok("never") => false,
73+
// `RUSTUP_TERM_COLOR` is prioritized over `NO_COLOR`.
74+
_ if process.var("NO_COLOR").is_ok() => false,
75+
_ => process.stderr().is_a_tty(),
76+
}
77+
};
6978
let logger = tracing_subscriber::fmt::layer()
7079
.with_writer(move || process.stderr())
7180
.with_ansi(has_ansi);

0 commit comments

Comments
 (0)