Base: Add a basic logging system
This commit is contained in:
parent
b76c2c54b3
commit
f5e282dc50
41
src/log.rs
Normal file
41
src/log.rs
Normal 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);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod db;
|
||||
mod log;
|
||||
|
||||
fn main() {
|
||||
db::get_backend("redis");
|
||||
|
Loading…
Reference in New Issue
Block a user