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

Log to stderr by default. #1266

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/cli-logging.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
6 changes: 3 additions & 3 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/wasm2obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down