Skip to content

Commit

Permalink
Wasmtime: omit ANSI color sequences in logging when not a terminal.
Browse files Browse the repository at this point in the history
In bytecodealliance#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 bytecodealliance#7435.
  • Loading branch information
cfallin committed Nov 1, 2023
1 parent 694f792 commit fcd2aff
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down

0 comments on commit fcd2aff

Please sign in to comment.