From 64b2293e2607414923128ba9be3e0caf3bde433c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 13 Oct 2023 20:48:36 -0700 Subject: [PATCH] Minor logging tweaks Some things I noticed from #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`. --- Cargo.lock | 3 +-- Cargo.toml | 1 - crates/cli-flags/Cargo.toml | 2 +- crates/cli-flags/src/lib.rs | 10 +++++++++- src/bin/wasmtime.rs | 10 ---------- tests/all/cli_tests.rs | 6 +----- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b6e0bb5a7f0..9046254b1f01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3393,7 +3393,6 @@ dependencies = [ "tempfile", "test-programs-artifacts", "tokio", - "tracing-subscriber", "walkdir", "wasm-encoder", "wasmparser", @@ -3423,8 +3422,8 @@ dependencies = [ "clap", "file-per-thread-logger", "humantime 2.1.0", - "pretty_env_logger 0.5.0", "rayon", + "tracing-subscriber", "wasmtime", ] diff --git a/Cargo.toml b/Cargo.toml index ec36b875ec19..8ca8a729c094 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/crates/cli-flags/Cargo.toml b/crates/cli-flags/Cargo.toml index e15b4d14f149..725c76267781 100644 --- a/crates/cli-flags/Cargo.toml +++ b/crates/cli-flags/Cargo.toml @@ -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" diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs index db5ba3abc300..13efde1dcbaa 100644 --- a/crates/cli-flags/src/lib.rs +++ b/crates/cli-flags/src/lib.rs @@ -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; @@ -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(); } } diff --git a/src/bin/wasmtime.rs b/src/bin/wasmtime.rs index 6e289a74b0f3..46868b3aca05 100644 --- a/src/bin/wasmtime.rs +++ b/src/bin/wasmtime.rs @@ -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() } diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs index a114e2a3e2be..997738cdd848 100644 --- a/tests/all/cli_tests.rs +++ b/tests/all/cli_tests.rs @@ -32,7 +32,7 @@ pub fn get_wasmtime_command() -> Result { // 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 { @@ -44,10 +44,6 @@ pub fn get_wasmtime_command() -> Result { Command::new(&me) }; - if let Ok(val) = std::env::var("WASMTIME_LOG") { - cmd.env("WASMTIME_LOG", val); - } - Ok(cmd) }