xref: /wasmtime-44.0.1/docs/cli-logging.md (revision adff9d9d)
1# Logging in the `wasmtime` CLI
2
3Wasmtime's libraries use Rust's [`log`] crate to log diagnostic
4information, and the `wasmtime` CLI executable uses [`tracing-subscriber`]
5for displaying this information on the console.
6
7Basic logging is controlled by the `WASMTIME_LOG` environment variable. For example,
8To enable logging of WASI system calls, similar to the `strace` command on Linux,
9set `WASMTIME_LOG=wasmtime_wasi=trace`. For more information on specifying
10filters, see [tracing-subscriber's EnvFilter docs].
11
12```shell-session
13$ WASMTIME_LOG=wasmtime_wasi=trace wasmtime hello.wasm
14[...]
15TRACE wiggle abi{module="wasi_snapshot_preview1" function="fd_write"} wasmtime_wasi::preview1::wasi_snapshot_preview1                     > fd=Fd(1) iovs=*guest 0x14/1
16Hello, world!
17TRACE wiggle abi{module="wasi_snapshot_preview1" function="fd_write"}: wasmtime_wasi::preview1::wasi_snapshot_preview1: result=Ok(14)
18TRACE wiggle abi{module="wasi_snapshot_preview1" function="proc_exit"}: wasmtime_wasi::preview1::wasi_snapshot_preview1: rval=1
19TRACE wiggle abi{module="wasi_snapshot_preview1" function="proc_exit"}: wasmtime_wasi::preview1::wasi_snapshot_preview1: result=Exited with i32 exit status 1
20```
21
22Wasmtime can also redirect the log messages into log files, with the
23`-D log-to-files` option. It creates one file per thread within Wasmtime, with
24the files named `wasmtime.dbg.*`.
25
26Additional environment variables that work with `WASMTIME_LOG` (__not__ `-D log-to-files`):
27 - `WASMTIME_LOG_NO_CONTEXT`: if set to `1`, removes the time, level and target from output.
28
29[`log`]: https://crates.io/crates/log
30[`tracing-subscriber`]: https://crates.io/crates/tracing-subscriber
31[tracing-subscriber's EnvFilter docs]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
32