Skip to content

Commit

Permalink
Minor logging tweaks
Browse files Browse the repository at this point in the history
Some things I noticed from bytecodealliance#7239 which are very much not critical but I
figure might be nice-to-haves:

* Move the logging configuration to the `wasmtime-cli-flags` crate with
  the other logging configuration to keep it in one place.
* Remove `pretty_env_logger` since `tracing-subscriber` probably
  supplants it.
* Don't explicitly inherit env vars in tests since that happens
  automatically with `Command`.
  • Loading branch information
alexcrichton committed Oct 14, 2023
1 parent f7f22f0 commit 64b2293
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ wasmtime-runtime = { workspace = true }
clap = { workspace = true, features = ["color", "suggestions", "derive"] }
anyhow = { workspace = true }
target-lexicon = { workspace = true }
tracing-subscriber = { workspace = true }
once_cell = { workspace = true }
listenfd = "1.0.0"
wat = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition.workspace = true
anyhow = { workspace = true }
clap = { workspace = true }
file-per-thread-logger = { workspace = true }
pretty_env_logger = { workspace = true }
tracing-subscriber = { workspace = true }
rayon = "1.5.0"
wasmtime = { workspace = true }
humantime = "2.0.0"
Expand Down
10 changes: 9 additions & 1 deletion crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

use anyhow::Result;
use clap::Parser;
use std::io::IsTerminal;
use std::time::Duration;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
use wasmtime::Config;

pub mod opt;
Expand Down Expand Up @@ -328,7 +330,13 @@ impl CommonOptions {
let prefix = "wasmtime.dbg.";
init_file_per_thread_logger(prefix);
} else {
pretty_env_logger::init();
let mut 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);
}
b.init();
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/bin/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ impl Wasmtime {
}

fn main() -> Result<()> {
use std::io::IsTerminal;
use tracing_subscriber::{EnvFilter, FmtSubscriber};

let mut 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);
}
b.init();
Wasmtime::parse().execute()
}

Expand Down
6 changes: 1 addition & 5 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn get_wasmtime_command() -> Result<Command> {
// If we're running tests with a "runner" then we might be doing something
// like cross-emulation, so spin up the emulator rather than the tests
// itself, which may not be natively executable.
let mut cmd = if let Some((_, runner)) = runner {
let cmd = if let Some((_, runner)) = runner {
let mut parts = runner.split_whitespace();
let mut cmd = Command::new(parts.next().unwrap());
for arg in parts {
Expand All @@ -44,10 +44,6 @@ pub fn get_wasmtime_command() -> Result<Command> {
Command::new(&me)
};

if let Ok(val) = std::env::var("WASMTIME_LOG") {
cmd.env("WASMTIME_LOG", val);
}

Ok(cmd)
}

Expand Down

0 comments on commit 64b2293

Please sign in to comment.