mpd_info_screen/src/debug_log.rs

72 lines
1.2 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
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum LogState {
ERROR,
WARNING,
DEBUG,
VERBOSE,
}
arg_enum! {
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum LogLevel {
ERROR,
WARNING,
DEBUG,
VERBOSE,
}
}
pub fn log<T>(msg: T, state: LogState, level: LogLevel)
where
T: Display,
{
if state == LogState::ERROR {
log_error(msg);
} else if state == LogState::WARNING {
if level != LogLevel::ERROR {
log_warning(msg);
}
} else if state == LogState::DEBUG {
if level == LogLevel::DEBUG || level == LogLevel::VERBOSE {
log_debug(msg);
}
} else if state == LogState::VERBOSE {
if level == LogLevel::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
}