mpd_info_screen/src/debug_log.rs

64 lines
1.1 KiB
Rust
Raw Normal View History

2021-12-14 12:40:53 +00:00
use std::fmt::Display;
use structopt::clap::arg_enum;
2021-12-14 12:40:53 +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,
{
println!("DEBUG: {}", msg);
2021-12-14 12:40:53 +00:00
}
pub fn log_verbose<T>(msg: T)
2021-12-14 12:40:53 +00:00
where
T: Display,
{
println!("VERBOSE: {}", msg);
2021-12-14 12:40:53 +00:00
}