Base: Add a basic logging system

This commit is contained in:
ProtoByter 2022-09-06 17:24:23 +01:00
parent b76c2c54b3
commit f5e282dc50
2 changed files with 42 additions and 0 deletions

41
src/log.rs Normal file
View File

@ -0,0 +1,41 @@
use std::fmt::{Display, Formatter, Write};
pub enum LogType {
Info,
Warn,
Error,
Debug,
Trace,
}
pub enum LogArea {
Net,
Db,
Node
}
impl Display for LogType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
LogType::Info => "INFO",
LogType::Warn => "WARN",
LogType::Error => "ERROR",
LogType::Debug => "DEBUG",
LogType::Trace => "TRACE",
})
}
}
impl Display for LogArea {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
LogArea::Net => "NET",
LogArea::Db => "DB",
LogArea::Node => "NODE",
})
}
}
pub fn log(log_type: LogType, log_area: LogArea, message: &str) {
println!("[{}] [{}] {}", log_type, log_area, message);
}

View File

@ -1,4 +1,5 @@
mod db;
mod log;
fn main() {
db::get_backend("redis");