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 {
2022-01-13 01:07:01 +00:00
Error,
Warning,
Debug,
Verbose,
}
arg_enum! {
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum LogLevel {
2022-01-13 01:07:01 +00:00
Error,
Warning,
Debug,
Verbose,
}
}
pub fn log<T>(msg: T, state: LogState, level: LogLevel)
where
T: Display,
{
2022-01-13 01:07:01 +00:00
if state == LogState::Error {
log_error(msg);
2022-01-13 01:07:01 +00:00
} else if state == LogState::Warning {
if level != LogLevel::Error {
log_warning(msg);
}
2022-01-13 01:07:01 +00:00
} else if state == LogState::Debug {
if level == LogLevel::Debug || level == LogLevel::Verbose {
log_debug(msg);
}
2022-01-13 01:07:01 +00:00
} else if state == LogState::Verbose {
if level == LogLevel::Verbose {
log_verbose(msg);
}
} else {
unreachable!();
}
}
pub fn log_error<T>(msg: T)
where
T: Display,
{
2022-01-13 01:07:01 +00:00
println!("Error: {}", msg);
}
pub fn log_warning<T>(msg: T)
where
T: Display,
{
2022-01-13 01:07:01 +00:00
println!("Warning: {}", msg);
}
pub fn log_debug<T>(msg: T)
2021-12-14 12:40:53 +00:00
where
T: Display,
{
2022-01-13 01:07:01 +00:00
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,
{
2022-01-13 01:07:01 +00:00
println!("Verbose: {}", msg);
2021-12-14 12:40:53 +00:00
}