diff --git a/Cargo.lock b/Cargo.lock index 9a1209de..d22c82c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1677,9 +1677,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "mach" @@ -3150,6 +3150,7 @@ dependencies = [ "anyhow", "clap", "env_logger 0.10.2", + "log", "prettytable-rs", "reqwest", "wws-config", diff --git a/Cargo.toml b/Cargo.toml index d70d0d0b..bd65d811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs index 9faa6862..5c0dc9c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -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, @@ -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