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

Changed logging to warn level when web client is built in release mode. #588

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

chris-dietz
Copy link
Collaborator

@chris-dietz chris-dietz commented Aug 23, 2024

Follow up from web client PR lowering the logging level on release builds.

@chris-dietz chris-dietz requested a review from ia0 as a code owner August 23, 2024 16:14
Copy link
Member

@ia0 ia0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not really what I meant in #549 (review):

If trunk doesn't build in release by default, it's definitely needed to do that. And speaking of release, maybe there's too much logging to the console. Instead of use wasm_logger::Config::default() we should use wasm_logger::Config::new(level) with appropriate level. This probably needs to be done at compile-time using features (one per log::Level) and set in the host runner when building trunk using log::max_level().to_level() to know which feature to use. If no feature is passed (i.e. when to_level() returns None), then logging should be completely disabled. But this should be done in a separate PR.

The idea is to have one feature per log level in web-client. Then in runner-host when calling trunk we check log::max_level().to_level() and enable the appropriate feature. If no feature is selected, web-client should not log anything. This lets the user control the level of logging instead of having something hard-coded.

web_client_log_level_debug = []
web_client_log_level_warn = []
web_client_log_level_error = []
web_client_log_level_trace = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to put this table before the [lints] one, because the sync script assumes [lints] is the last one. We can also use much simple feature names:

[features]
# At most one log level can be selected (defaults to off).
log_debug = []
log_error = []
...

let mut trunk = tokio::process::Command::new("../../scripts/wrapper.sh");
trunk.args(["trunk", "build", "--release", "crates/web-client/index.html"]);
wasefire_cli_tools::cmd::execute(&mut trunk).await?;
let mut trunk = std::process::Command::new("../../scripts/wrapper.sh");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You reverted the tokio::process and --locked changes while merging.

trunk.args(["trunk", "build", "--release", "crates/web-client/index.html"]);
wasefire_cli_tools::cmd::execute(&mut trunk).await?;
let mut trunk = std::process::Command::new("../../scripts/wrapper.sh");
trunk.args(["trunk", "build", "--locked", "--release", "--features=web_client_log_level_warn", "crates/web-client/index.html"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you're still working on computing this automatically.

fn main() {
wasm_logger::init(wasm_logger::Config::default());
wasm_logger::init(wasm_logger::Config::new(get_log_level()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could simply be something like this:

Suggested change
wasm_logger::init(wasm_logger::Config::new(get_log_level()));
#[cfg(feature = "log_trace")]
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
#[cfg(feature = "log_debug")]
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
#[cfg(feature = "log_info")]
wasm_logger::init(wasm_logger::Config::new(log::Level::Info));
#[cfg(feature = "log_warn")]
wasm_logger::init(wasm_logger::Config::new(log::Level::Warn));
#[cfg(feature = "log_error")]
wasm_logger::init(wasm_logger::Config::new(log::Level::Error));

Then we don't need the cfg_if dependency and when no features are selected, logging is disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants