bugfix, implemented verbose logging cli option
Some checks failed
Test the running changes / Test (push) Failing after 38s
Some checks failed
Test the running changes / Test (push) Failing after 38s
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
//! Simple and program specific command line argument parsing solution.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
use crate::error::ErrorKind;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
pub static VERBOSE: OnceLock<bool> = OnceLock::new();
|
||||
|
||||
pub struct ProgramArgs {
|
||||
pub outdir: PathBuf,
|
||||
@@ -12,6 +13,7 @@ pub struct ProgramArgs {
|
||||
pub generate: bool,
|
||||
pub force: bool,
|
||||
pub addr: String,
|
||||
pub verbose: bool,
|
||||
}
|
||||
|
||||
impl Default for ProgramArgs {
|
||||
@@ -22,6 +24,7 @@ impl Default for ProgramArgs {
|
||||
generate: false,
|
||||
force: false,
|
||||
addr: "0.0.0.0:8080".to_string(),
|
||||
verbose: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,11 +53,16 @@ impl TryFrom<std::env::Args> for ProgramArgs {
|
||||
}
|
||||
"-g" => a.generate = true,
|
||||
"-f" => a.force = true,
|
||||
"-v" => {
|
||||
a.verbose = true;
|
||||
VERBOSE.get_or_init(|| true);
|
||||
}
|
||||
_ => {
|
||||
a.outdir = v.into();
|
||||
}
|
||||
}
|
||||
}
|
||||
VERBOSE.get_or_init(|| false);
|
||||
Ok(a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::fmt::Display;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(PartialEq)]
|
||||
pub enum Level {
|
||||
Error,
|
||||
Warn,
|
||||
@@ -30,13 +31,15 @@ impl Display for Level {
|
||||
#[macro_export]
|
||||
macro_rules! log {
|
||||
($level:expr, $($arg:tt)*) => {{
|
||||
println!(
|
||||
"{} {}:{}:{}: {}",
|
||||
$level,
|
||||
std::module_path!(),
|
||||
std::file!(),
|
||||
std::line!(),
|
||||
format!($($arg)*)
|
||||
);
|
||||
if $level != Level::Debug || crate::args::VERBOSE.get().unwrap().to_owned() {
|
||||
println!(
|
||||
"{} {}:{}:{}: {}",
|
||||
$level,
|
||||
std::module_path!(),
|
||||
std::file!(),
|
||||
std::line!(),
|
||||
format!($($arg)*)
|
||||
);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -119,7 +119,9 @@ impl HttpResponse {
|
||||
let _ = std::io::Read::read(stream, &mut [0u8; 1]);
|
||||
*/
|
||||
|
||||
log!(Level::Info, "\n{}", &self);
|
||||
// todo better verbose tracking
|
||||
log!(Level::Info, "{} {}", self.version, self.status);
|
||||
log!(Level::Debug, "\n{}", &self);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user