Skip to content

Commit

Permalink
switch default log level to "error", add -v to run (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeshaw authored Jul 19, 2023
1 parent 6bdfda0 commit 7a8e569
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
16 changes: 12 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ pub async fn main() -> ExitCode {
let cmd = opts.command.unwrap_or(Commands::Serve(opts.serve));
match cmd {
Commands::Run(run_args) => {
install_tracing_subscriber(0);
install_tracing_subscriber(run_args.shared().verbosity());
match run_wasm_main(run_args).await {
Ok(_) => ExitCode::SUCCESS,
Err(e) => get_exit_code(e),
Err(e) => {
// Suppress stack trace if the error is due to a
// normal call to proc_exit, leading to a process
// exit.
if !e.is::<I32Exit>() {
event!(Level::ERROR, "{}", e);
}
get_exit_code(e)
}
}
}
Commands::Serve(serve_args) => {
install_tracing_subscriber(serve_args.verbosity());
install_tracing_subscriber(serve_args.shared().verbosity());
match {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
Expand Down Expand Up @@ -104,7 +112,7 @@ fn install_tracing_subscriber(verbosity: u8) {
// viceroy and viceroy-lib so that they can have output in the terminal
if env::var("RUST_LOG").ok().is_none() {
match verbosity {
0 => env::set_var("RUST_LOG", "viceroy=off,viceroy-lib=off"),
0 => env::set_var("RUST_LOG", "viceroy=error,viceroy-lib=error"),
1 => env::set_var("RUST_LOG", "viceroy=info,viceroy-lib=info"),
2 => env::set_var("RUST_LOG", "viceroy=debug,viceroy-lib=debug"),
_ => env::set_var("RUST_LOG", "viceroy=trace,viceroy-lib=trace"),
Expand Down
25 changes: 12 additions & 13 deletions cli/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ pub struct ServeArgs {
#[arg(long = "addr")]
socket_addr: Option<SocketAddr>,

/// Verbosity of logs for Viceroy. `-v` sets the log level to DEBUG and
/// `-vv` to TRACE. This option will not take effect if you set RUST_LOG
/// to a value before starting Viceroy
#[arg(short = 'v', action = clap::ArgAction::Count)]
verbosity: u8,

#[command(flatten)]
shared: SharedArgs,
}
Expand Down Expand Up @@ -91,6 +85,11 @@ pub struct SharedArgs {
/// Set of experimental WASI modules to link against.
#[arg(value_enum, long = "experimental_modules", required = false)]
experimental_modules: Vec<ExperimentalModuleArg>,
/// Verbosity of logs for Viceroy. `-v` sets the log level to INFO,
/// `-vv` to DEBUG, and `-vvv` to TRACE. This option will not take
/// effect if you set RUST_LOG to a value before starting Viceroy
#[arg(short = 'v', action = clap::ArgAction::Count)]
verbosity: u8,
}

impl ServeArgs {
Expand All @@ -100,13 +99,6 @@ impl ServeArgs {
.unwrap_or_else(|| SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7676))
}

/// Verbosity of logs for Viceroy. `-v` sets the log level to DEBUG and
/// `-vv` to TRACE. This option will not take effect if you set RUST_LOG
/// to a value before starting Viceroy
pub fn verbosity(&self) -> u8 {
self.verbosity
}

pub fn shared(&self) -> &SharedArgs {
&self.shared
}
Expand Down Expand Up @@ -158,6 +150,13 @@ impl SharedArgs {
pub fn wasi_modules(&self) -> HashSet<ExperimentalModule> {
self.experimental_modules.iter().map(|x| x.into()).collect()
}

/// Verbosity of logs for Viceroy. `-v` sets the log level to DEBUG and
/// `-vv` to TRACE. This option will not take effect if you set RUST_LOG
/// to a value before starting Viceroy
pub fn verbosity(&self) -> u8 {
self.verbosity
}
}

/// Enum of available (experimental) wasi modules
Expand Down

0 comments on commit 7a8e569

Please sign in to comment.