Skip to content

Commit

Permalink
Add WASMTIME_LOG_NO_CONTEXT (#9902)
Browse files Browse the repository at this point in the history
* Documentation

* Add WASMTIME_LOG_NO_CONTEXT

When using trace logging for compiler debugging, the usual
'context': time, level, target, are just visual noise.

Add an environment variable to disable them.
  • Loading branch information
SingleAccretion authored Dec 26, 2024
1 parent f64a9d5 commit 41ff8e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,19 @@ impl CommonOptions {
} else {
use std::io::IsTerminal;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
let b = FmtSubscriber::builder()
let builder = FmtSubscriber::builder()
.with_writer(std::io::stderr)
.with_env_filter(EnvFilter::from_env("WASMTIME_LOG"))
.with_ansi(std::io::stderr().is_terminal());
b.init();
if std::env::var("WASMTIME_LOG_NO_CONTEXT").is_ok_and(|value| value.eq("1")) {
builder
.with_level(false)
.with_target(false)
.without_time()
.init()
} else {
builder.init();
}
}
#[cfg(not(feature = "logging"))]
if self.debug.log_to_files == Some(true) || self.debug.logging == Some(true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ impl<'a> fmt::Debug for DieDetailedSummary<'a> {
AttributeValue::CallingConvention(value) => write!(f, "{value}"),
AttributeValue::Inline(value) => write!(f, "{value}"),
AttributeValue::Ordering(value) => write!(f, "{value}"),
AttributeValue::UnitRef(offset) => write!(f, "0x{:08x}", offset.0),
AttributeValue::UnitRef(offset) => {
let section_offset = offset.to_unit_section_offset(unit);
write!(f, "0x{:08x}", get_offset_value(section_offset))
}
AttributeValue::DebugInfoRef(offset) => write!(f, "0x{:08x}", offset.0),
unexpected_attr => write!(f, "<unexpected attr: {unexpected_attr:?}>"),
}?;
Expand Down
3 changes: 3 additions & 0 deletions docs/cli-logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Wasmtime can also redirect the log messages into log files, with the
`-D log-to-files` option. It creates one file per thread within Wasmtime, with
the files named `wasmtime.dbg.*`.

Additional environment variables that work with `WASMTIME_LOG` (__not__ `-D log-to-files`):
- `WASMTIME_LOG_NO_CONTEXT`: if set to `1`, removes the time, level and target from output.

[`log`]: https://crates.io/crates/log
[`tracing-subscriber`]: https://crates.io/crates/tracing-subscriber
[tracing-subscriber's EnvFilter docs]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives

0 comments on commit 41ff8e7

Please sign in to comment.