logging macros

This commit is contained in:
elfein727 2021-12-24 01:39:24 -08:00
parent c8455f9352
commit 37daece60a

View file

@ -1,24 +1,52 @@
pub trait Log { pub trait Log {
fn debug(val: &str); fn debug(val: &str);
fn error(); fn error();
fn info(val: &str); fn info(val: &str);
fn trace(); fn trace();
} }
use crate::serial_print; use crate::serial_print;
use lliw::{Fg, Reset}; use lliw::{Fg, Reset};
pub struct ANSISerialLogger; pub struct ANSISerialLogger;
impl Log for ANSISerialLogger { impl Log for ANSISerialLogger {
fn debug(val: &str) { fn debug(val: &str) {
serial_print!("[{}Debug{}] {}\n", Fg::Blue, Reset, val); serial_print!("[{}Debug{}] {}\n", Fg::Blue, Reset, val);
} }
fn error() { fn error() {
todo!(); todo!();
} }
fn info(val: &str) { fn info(val: &str) {
serial_print!("[{}Info{}] {}\n", Fg::Blue, Reset, val); serial_print!("[{}Info{}] {}\n", Fg::Blue, Reset, val);
} }
fn trace() { fn trace() {
todo!(); todo!();
} }
}
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => ({
log::ANSISerialLogger::debug(&format!($($arg)*));
})
}
#[macro_export]
macro_rules! error {
($($arg:tt)*) => ({
log::ANSISerialLogger::error(&format!($($arg)*));
})
}
#[macro_export]
macro_rules! info {
($($arg:tt)*) => ({
log::ANSISerialLogger::info(&format!($($arg)*));
})
}
#[macro_export]
macro_rules! trace {
($($arg:tt)*) => ({
log::ANSISerialLogger::trace(&format!($($arg)*));
})
} }