Skip to content
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

WASMTIME_LOG output emits ANSI sequences when redirecting stderr to file #7435

Closed
cfallin opened this issue Nov 1, 2023 · 0 comments · Fixed by #7436
Closed

WASMTIME_LOG output emits ANSI sequences when redirecting stderr to file #7435

cfallin opened this issue Nov 1, 2023 · 0 comments · Fixed by #7436

Comments

@cfallin
Copy link
Member

cfallin commented Nov 1, 2023

In #7239 we added a tracing-log subscriber that prints log output to stderr when the WASMTIME_LOG environment variable is set. This is useful for debugging, but unfortunately its ANSI color sequence heuristics seem somewhat broken: on Linux, if I run

$ WASMTIME_LOG=tracing wasmtime compile ... 2>log

I see a log file that looks like

    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/wasmtime compile --target aarch64 -C pcc=yes -O static-memory-maximum-size=0 ./test.wat`
^[[2m2023-11-01T04:49:35.596710Z^[[0m ^[[34mDEBUG^[[0m ^[[2mwasmtime_cache::worker^[[0m^[[2m:^[[0m Cache worker thread started.
^[[2m2023-11-01T04:49:35.596813Z^[[0m ^[[34mDEBUG^[[0m ^[[2mwasmtime_cache::worker^[[0m^[[2m:^[[0m New nice value of worker thread: 3
^[[2m2023-11-01T04:49:35.600299Z^[[0m ^[[34mDEBUG^[[0m ^[[2mcranelift_codegen::timing^[[0m^[[2m:^[[0m timing: Starting Translate WASM function, (during <no pass>)
^[[2m2023-11-01T04:49:35.600374Z^[[0m ^[[35mTRACE^[[0m ^[[2mcranelift_wasm::func_translator^[[0m^[[2m:^[[0m translate(12 bytes, u0:0(i64 vmctx, i64, i32) -> i32 fast)
^[[2m2023-11-01T04:49:35.600595Z^[[0m ^[[34mDEBUG^[[0m ^[[2mcranelift_codegen::timing^[[0m^[[2m:^[[0m timing: Starting Compilation passes, (during <no pass>)
^[[2m2023-11-01T04:49:35.600669Z^[[0m ^[[34mDEBUG^[[0m ^[[2mcranelift_codegen::context^[[0m^[[2m:^[[0m Number of CLIF instructions to optimize: 12
^[[2m2023-11-01T04:49:35.600694Z^[[0m ^[[34mDEBUG^[[0m ^[[2mcranelift_codegen::context^[[0m^[[2m:^[[0m Number of CLIF blocks to optimize: 1
^[[2m2023-11-01T04:49:35.600716Z^[[0m ^[[35mTRACE^[[0m ^[[2mcranelift_codegen::context^[[0m^[[2m:^[[0m Optimizing (opt level Speed):

The code does indeed check whether stderr is a terminal before enabling ANSI sequences; but somehow this is not working right.

cfallin added a commit to cfallin/wasmtime that referenced this issue Nov 1, 2023
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.
github-merge-queue bot pushed a commit that referenced this issue Nov 1, 2023
…7436)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant