Skip to content

Commit

Permalink
feat: configure maximum logging level (#1)
Browse files Browse the repository at this point in the history
* feat: Add `--log-level` option to wws
  • Loading branch information
sea-grass authored Jun 3, 2024
1 parent 6985faa commit ba965ce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ path = "src/main.rs"
[dependencies]
actix-web = { workspace = true }
anyhow = "1.0.66"
log = "0.4.21"
env_logger = "0.10.0"
clap = { version = "4.0.10", features = ["derive"] }
prettytable-rs = "0.10.0"
Expand Down
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ use crate::utils::runtimes::install_missing_runtimes;
use clap::Parser;
use commands::main::Main;
use commands::runtimes::RuntimesCommands;
use log::LevelFilter;
use std::io::{Error, ErrorKind};
use std::path::PathBuf;
use std::process::exit;
use std::str::FromStr;
use wws_config::Config;
use wws_project::{identify_type, prepare_project, ProjectType};
use wws_router::Routes;
Expand Down Expand Up @@ -45,6 +47,9 @@ pub struct Args {
#[arg(long, short)]
install_runtimes: bool,

#[arg(short, long, value_parser = LevelFilter::from_str, default_value = "info")]
log_level: LevelFilter,

/// Set the commit when using a git repository as project
#[arg(long)]
git_commit: Option<String>,
Expand Down Expand Up @@ -78,7 +83,18 @@ pub struct Args {
async fn main() -> std::io::Result<()> {
let args = Args::parse();

std::env::set_var("RUST_LOG", "actix_web=info");
match std::env::var("RUST_LOG") {
Ok(_) => {}
Err(_) => match args.log_level {
LevelFilter::Off => std::env::set_var("RUST_LOG", ""),
LevelFilter::Error => std::env::set_var("RUST_LOG", "actix_web=error"),
LevelFilter::Warn => std::env::set_var("RUST_LOG", "actix_web=warn"),
LevelFilter::Info => std::env::set_var("RUST_LOG", "actix_web=info"),
LevelFilter::Debug => std::env::set_var("RUST_LOG", "actix_web=debug"),
LevelFilter::Trace => std::env::set_var("RUST_LOG", "actix_web=trace"),
},
}

env_logger::init();

// Check the given subcommand
Expand Down

0 comments on commit ba965ce

Please sign in to comment.