The website generator used to generate the webpage at teasca.de, but can be used to generate any webpage with any content.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
1.4 KiB

use ansi_term::Color::{Blue, Cyan, Red, Yellow};
pub struct Logger {
log_level: LogLevel,
}
impl Logger {
pub fn new(log_level: LogLevel) -> Logger {
Logger { log_level }
}
pub fn log<T: Into<String>>(&self, log_level: LogLevel, message: T) {
if self.log_level.clone() as i32 >= log_level.clone() as i32 {
match log_level {
LogLevel::QUIET => (),
LogLevel::SEVERE => eprintln!("{}: {}", Red.paint("[SEVERE]"), message.into()),
LogLevel::INFO => println!("{}: {}", Cyan.paint("[INFO]"), message.into()),
LogLevel::WARNING => println!("{}: {}", Yellow.paint("[WARNING]"), message.into()),
LogLevel::DETAIL => println!("{}: {}", Blue.paint("[DETAIL]"), message.into()),
LogLevel::DETAILER => println!("{}: {}", Blue.paint("[DETAILER]"), message.into()),
}
}
}
}
#[allow(dead_code)]
#[derive(Clone, Debug)]
#[repr(u8)]
pub enum LogLevel {
QUIET = 0,
SEVERE = 1,
INFO = 2,
WARNING = 3, // Default
DETAIL = 4,
DETAILER = 5,
}
impl From<u8> for LogLevel {
fn from(number: u8) -> LogLevel {
match number {
0 => LogLevel::QUIET,
1 => LogLevel::SEVERE,
2 => LogLevel::INFO,
4 => LogLevel::DETAIL,
5 => LogLevel::DETAILER,
_ => LogLevel::WARNING, // 3, also fallback
}
}
}