2021-12-14 12:40:53 +00:00
|
|
|
use std::fmt::Display;
|
2021-12-20 08:41:03 +00:00
|
|
|
use structopt::clap::arg_enum;
|
2021-12-14 12:40:53 +00:00
|
|
|
|
2021-12-20 08:41:03 +00:00
|
|
|
arg_enum! {
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
|
|
|
pub enum LogState {
|
|
|
|
ERROR,
|
|
|
|
WARNING,
|
|
|
|
DEBUG,
|
|
|
|
VERBOSE,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn log<T>(msg: T, level: LogState, state: LogState)
|
|
|
|
where
|
|
|
|
T: Display,
|
|
|
|
{
|
|
|
|
if level == LogState::ERROR {
|
|
|
|
log_error(msg);
|
|
|
|
} else if level == LogState::WARNING {
|
|
|
|
if state != LogState::ERROR {
|
|
|
|
log_warning(msg);
|
|
|
|
}
|
|
|
|
} else if level == LogState::DEBUG {
|
|
|
|
if state == LogState::DEBUG || state == LogState::VERBOSE {
|
|
|
|
log_debug(msg);
|
|
|
|
}
|
|
|
|
} else if level == LogState::VERBOSE {
|
|
|
|
if state == LogState::VERBOSE {
|
|
|
|
log_verbose(msg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn log_error<T>(msg: T)
|
|
|
|
where
|
|
|
|
T: Display,
|
|
|
|
{
|
|
|
|
println!("ERROR: {}", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn log_warning<T>(msg: T)
|
|
|
|
where
|
|
|
|
T: Display,
|
|
|
|
{
|
|
|
|
println!("WARNING: {}", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn log_debug<T>(msg: T)
|
2021-12-14 12:40:53 +00:00
|
|
|
where
|
|
|
|
T: Display,
|
|
|
|
{
|
2021-12-20 08:41:03 +00:00
|
|
|
println!("DEBUG: {}", msg);
|
2021-12-14 12:40:53 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 08:41:03 +00:00
|
|
|
pub fn log_verbose<T>(msg: T)
|
2021-12-14 12:40:53 +00:00
|
|
|
where
|
|
|
|
T: Display,
|
|
|
|
{
|
2021-12-20 08:41:03 +00:00
|
|
|
println!("VERBOSE: {}", msg);
|
2021-12-14 12:40:53 +00:00
|
|
|
}
|