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
Open
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
1 change: 1 addition & 0 deletions crates/runner-host/crates/web-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/runner-host/crates/web-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ publish = false
edition = "2021"

[dependencies]
cfg-if = "1.0.0"
gloo-utils = "0.2.0"
log = "0.4.21"
serde_json = "1.0.117"
Expand All @@ -21,3 +22,11 @@ yew-hooks = "0.3.2"
clippy.unit-arg = "allow"
rust.unsafe-op-in-unsafe-fn = "warn"
rust.unused-crate-dependencies = "warn"

[features]
web_client_log_level_info = []
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 = []
...


22 changes: 21 additions & 1 deletion crates/runner-host/crates/web-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,27 @@ mod board_components;
mod console;
mod hooks;

use cfg_if::cfg_if;

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.


yew::Renderer::<app::App>::new().render();
}

fn get_log_level() -> log::Level {
cfg_if! {
if #[cfg(feature = "web_client_log_level_trace")] {
log::Level::Trace
}
else if #[cfg(feature = "web_client_log_level_debug")] {
log::Level::Debug
} else if #[cfg(feature = "web_client_log_level_info")] {
log::Level::Info
} else if #[cfg(feature = "web_client_log_level_warn")] {
log::Level::Warn
} else {
log::Level::Error
}
}
}
6 changes: 3 additions & 3 deletions crates/runner-host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ async fn main() -> Result<()> {
}
}
});
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", "--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.

wasefire_cli_tools::cmd::execute(&mut trunk)?;
let url = format!("{}:{}", flags.web_options.web_host, flags.web_options.web_port);
web_server::Client::new(&url, sender).await?
};
Expand Down
Loading