use owo_colors::OwoColorize;
pub enum Level {
Info,
Warning,
Error,
}
#[derive(PartialEq, PartialOrd)]
pub enum Verbosity {
Normal = 0,
Verbose = 1,
Debug = 2,
}
impl Verbosity {
pub fn from_u8(verbosity: &u8) -> Self {
match verbosity {
0 => Verbosity::Normal,
1 => Verbosity::Verbose,
2 => Verbosity::Debug,
_ => Verbosity::Debug,
}
}
}
pub struct Log {
pub level: Level,
pub text: String,
pub verbose: Option<Verbosity>,
}
impl Log {
pub fn new(level: Level, text: String, verbose: Option<Verbosity>) -> Self {
Log {
level,
text,
verbose,
}
}
}
pub fn logger(log: Log, verbose: Option<Verbosity>) {
if verbose.unwrap_or(Verbosity::Debug) >= log.verbose.unwrap_or(Verbosity::Normal) {
match log.level {
Level::Info => {
println!("{}: {}", "Info".green(), log.text);
}
Level::Warning => {
println!("{}: {}", "Warning".yellow(), log.text);
}
Level::Error => {
eprintln!("{}: {}", "Error".red(), log.text);
}
}
}
}