-
Notifications
You must be signed in to change notification settings - Fork 824
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
Update logging to use log
, add command line flag to toggle it
#1147
Conversation
bors try |
a56d859
to
12f7416
Compare
bors try- |
bors try |
c03f2f1
to
397343e
Compare
bors try- |
bors try |
397343e
to
286e5db
Compare
Cargo.toml
Outdated
@@ -22,6 +22,9 @@ include = [ | |||
[dependencies] | |||
byteorder = "1.3" | |||
errno = "0.2" | |||
fern = { version = "0.5", features = ["colored"], optional = true } | |||
# statically turn off logging for wasmer by default, fetaures override this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# statically turn off logging for wasmer by default, fetaures override this | |
# statically turn off logging for wasmer by default, features override this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted this comment because it's no longer true!
src/utils.rs
Outdated
pub fn wasmer_should_print_color() -> bool { | ||
std::env::var("WASMER_DISABLE_COLOR") | ||
.map(|_| false) | ||
.unwrap_or(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.unwrap_or(stdout_isatty())
from the isatty
crate?
Which also implies that it shouldn't be WASMER_DISABLE_COLOR
because we might also want to forcibly enable color when isatty is false. Perhaps WASMER_COLORS
which may be true or false.
@@ -247,6 +248,11 @@ struct Run { | |||
#[structopt(long = "enable-experimental-io-devices", hidden = true)] | |||
enable_experimental_io_devices: bool, | |||
|
|||
/// Enable debug output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a canonical naming for the logging flags? I would expect that --debug
would map precisely to enabling debug!()
and above. Something like --log-level=...
which corresponds to the enum in Log::LevelFilter
, defaulting to Off
given that we conditionally initialize logging?
Or maybe we should set it to Error
or Warn
and always initialize logging? I like that even more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so currently I'm using Cargo features for this!
tryBuild failed
|
bors r+ |
1147: Update logging to use `log`, add command line flag to toggle it r=MarkMcCaskey a=MarkMcCaskey This PR: - ports our logging to the [`log`](https://crates.io/crates/log) crate which is the de-facto standard way to do logging in Rust (it defines a trait which logging backends can implement (we can also implement our own at a later date using these traits)). Another benefit of using the standard logging utilities is that we can now allow users of our libraries to filter and display log messages from Wasmer in a more natural way. - adds a command line flag to enable/disable logging - updates the `debug` and `trace` features to pass the correct static toggles to the `log` crate; judging by the `log` documentation these features need to only be set once - copies and slightly modifies our `fern` configuration from wapm - updates the makefile so that `make release` compiles out all log statements - TODO: update CI to not print with color (may not be necessary actually) # Review - [x] Add a short description of the the change to the CHANGELOG.md file Here's some example output: ``` [1579035881.809 DEBUG wasmer_wasi::state] wasi::fs::inodes [1579035881.809 DEBUG wasmer_wasi::state] wasi::fs::preopen_dirs [1579035881.809 DEBUG wasmer_wasi::state] wasi::fs::mapped_dirs [1579035881.809 DEBUG wasmer_wasi::state] wasi::fs::end [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::fd_prestat_get: fd=3 [1579035881.810 DEBUG wasmer_wasi::state] in prestat_fd Fd { rights: 536870911, rights_inheriting: 536870911, flags: 0, offset: 0, open_flags: 1, inode: Index { index: 3, generation: 0 } } [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::fd_prestat_dir_name: fd=3, path_len=2 [1579035881.810 DEBUG wasmer_wasi::syscalls] => result: "/" [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::fd_fdstat_get: fd=3, buf_ptr=1048536 [1579035881.810 DEBUG wasmer_wasi::state] fdstat: Fd { rights: 536870911, rights_inheriting: 536870911, flags: 0, offset: 0, open_flags: 1, inode: Index { index: 3, generation: 0 } } [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::fd_prestat_get: fd=4 [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::environ_sizes_get [1579035881.810 DEBUG wasmer_wasi::syscalls] env_var_count: 0, env_buf_size: 0 [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::args_sizes_get [1579035881.810 DEBUG wasmer_wasi::syscalls] => argc=3, argv_buf_size=92 [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::args_get [1579035881.810 DEBUG wasmer_wasi::syscalls] => args: 0: /Users/mark/.wasmer/globals/wapm_packages/mark/[email protected]/wasi-example.wasm 1: -e 2: HQ+ [1579035881.810 DEBUG wasmer_wasi::syscalls] wasi::args_sizes_get [1579035881.811 DEBUG wasmer_wasi::syscalls] => argc=3, argv_buf_size=92 [1579035881.811 DEBUG wasmer_wasi::syscalls] wasi::args_get [1579035881.811 DEBUG wasmer_wasi::syscalls] => args: 0: /Users/mark/.wasmer/globals/wapm_packages/mark/[email protected]/wasi-example.wasm 1: -e 2: HQ+ [1579035881.811 DEBUG wasmer_wasi::syscalls] wasi::random_get buf_len: 16 [1579035881.811 DEBUG wasmer_wasi::syscalls] wasi::fd_write: fd=1 Hello, world! [1579035881.811 DEBUG wasmer_wasi::syscalls] wasi::fd_write: fd=1 HQ+ ``` Co-authored-by: Mark McCaskey <[email protected]>
Build succeeded
|
This PR:
log
crate which is the de-facto standard way to do logging in Rust (it defines a trait which logging backends can implement (we can also implement our own at a later date using these traits)). Another benefit of using the standard logging utilities is that we can now allow users of our libraries to filter and display log messages from Wasmer in a more natural way.debug
andtrace
features to pass the correct static toggles to thelog
crate; judging by thelog
documentation these features need to only be set oncefern
configuration from wapmmake release
compiles out all log statementsReview
Here's some example output: