From c032446c3fe39bc512af0e91c41561db334ff056 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 9 Mar 2020 15:57:06 -0700 Subject: [PATCH] Log to stderr by default. Change the default from file-per-thread-logger to pretty-env-logger, which is more common in Rust projects, and change the option from `-d` to `--log-to-files`. --- docs/cli-logging.md | 26 ++++++++++++++++++++++++++ docs/cli.md | 4 ++-- src/commands/run.rs | 6 +++--- src/commands/wasm2obj.rs | 6 +++--- src/commands/wast.rs | 6 +++--- src/lib.rs | 6 +++--- 6 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 docs/cli-logging.md diff --git a/docs/cli-logging.md b/docs/cli-logging.md new file mode 100644 index 000000000000..333825328bea --- /dev/null +++ b/docs/cli-logging.md @@ -0,0 +1,26 @@ +# Logging in the `wasmtime` CLI + +Wasmtime's libraries use Rust's [`log`] crate to log diagnostic +information, and the `wasmtime` CLI executable uses [`pretty_env_logger`] +by default for logging this information to the console. + +Basic logging is controlled by the `RUST_LOG` environment variable. For example, +To enable logging of WASI system calls, similar to the `strace` command on Linux, +set `RUST_LOG=wasi_common=trace`. + +```sh +$ RUST_LOG=wasi_common=trace wasmtime hello.wasm +[...] + TRACE wasi_common::hostcalls_impl::fs > fd_write(fd=1, iovs_ptr=0x10408, iovs_len=1, nwritten=0x10404) +Hello, world! + TRACE wasi_common::hostcalls_impl::fs > | *nwritten=14 + TRACE wasi_common::hostcalls > | errno=ESUCCESS (No error occurred. System call completed successfully.) + TRACE wasi_common::hostcalls_impl::misc > proc_exit(rval=1) +``` + +Wasmtime can also redirect the log messages into log files, with the +`--log-to-files` option. It creates one file per thread within Wasmtime, with +the files named `wasmtime.dbg.*`. + +[`log`]: https://crates.io/crates/log +[`pretty_env_logger`]: https://crates.io/crates/pretty_env_logger diff --git a/docs/cli.md b/docs/cli.md index 3f861e1143f9..3dd408624747 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -20,5 +20,5 @@ $ wasmtime --invoke _start foo.wasm ``` For more information be sure to check out [how to install the -CLI](cli-install.md) as well as [the list of options you can -pass](cli-options.md). +CLI](cli-install.md), [the list of options you can +pass](cli-options.md), and [how to enable logging](cli-logging.md). diff --git a/src/commands/run.rs b/src/commands/run.rs index d5fa7ee0a886..7407f83c49f1 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -89,11 +89,11 @@ pub struct RunCommand { impl RunCommand { /// Executes the command. pub fn execute(&self) -> Result<()> { - if self.common.debug { - pretty_env_logger::init(); - } else { + if self.common.log_to_files { let prefix = "wasmtime.dbg."; init_file_per_thread_logger(prefix); + } else { + pretty_env_logger::init(); } let config = self.common.config()?; diff --git a/src/commands/wasm2obj.rs b/src/commands/wasm2obj.rs index 494857b2a2dc..dbfd89042bdd 100644 --- a/src/commands/wasm2obj.rs +++ b/src/commands/wasm2obj.rs @@ -54,11 +54,11 @@ impl WasmToObjCommand { } fn handle_module(&self) -> Result<()> { - if self.common.debug { - pretty_env_logger::init(); - } else { + if self.common.log_to_files { let prefix = "wasm2obj.dbg."; init_file_per_thread_logger(prefix); + } else { + pretty_env_logger::init(); } let cache_config = if self.common.disable_cache { diff --git a/src/commands/wast.rs b/src/commands/wast.rs index 4ac459319aea..d09fba9841d7 100644 --- a/src/commands/wast.rs +++ b/src/commands/wast.rs @@ -26,11 +26,11 @@ pub struct WastCommand { impl WastCommand { /// Executes the command. pub fn execute(&self) -> Result<()> { - if self.common.debug { - pretty_env_logger::init(); - } else { + if self.common.log_to_files { let prefix = "wast.dbg."; init_file_per_thread_logger(prefix); + } else { + pretty_env_logger::init(); } let config = self.common.config()?; diff --git a/src/lib.rs b/src/lib.rs index dc9b1bfca2ff..89c5f417a526 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,9 +88,9 @@ struct CommonOptions { #[structopt(long, conflicts_with = "lightbeam")] cranelift: bool, - /// Enable debug output - #[structopt(short, long)] - debug: bool, + /// Log to per-thread log files instead of stderr. + #[structopt(long)] + log_to_files: bool, /// Generate debug information #[structopt(short = "g")]