From fcd2aff52287099557eb615ce3e5c19e5c836427 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Tue, 31 Oct 2023 22:01:14 -0700 Subject: [PATCH] Wasmtime: omit ANSI color sequences in logging when not a terminal. In #7239 we added a `tracing-log` subscriber that prints logs to stderr if enabled with an environment variable. It included logic to add ANSI color sequences when stderr is a terminal, for legibility. Unfortunately it seems that while this logic *enabled* colors on a terminal, it did not *disable* colors on a non-terminal; so redirects of stderr to a file would result in ANSI color sequences being captured in that file. Specifically, the builder seems not to default to no-color; so rather than enable-or-nothing, we should explicitly enable or disable always. Fixes #7435. --- crates/cli-flags/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs index 31b0232b22d8..871ade5050ef 100644 --- a/crates/cli-flags/src/lib.rs +++ b/crates/cli-flags/src/lib.rs @@ -356,12 +356,10 @@ impl CommonOptions { } else { use std::io::IsTerminal; use tracing_subscriber::{EnvFilter, FmtSubscriber}; - let mut b = FmtSubscriber::builder() + let b = FmtSubscriber::builder() .with_writer(std::io::stderr) - .with_env_filter(EnvFilter::from_env("WASMTIME_LOG")); - if std::io::stderr().is_terminal() { - b = b.with_ansi(true); - } + .with_env_filter(EnvFilter::from_env("WASMTIME_LOG")) + .with_ansi(std::io::stderr().is_terminal()); b.init(); } #[cfg(not(feature = "logging"))]