master > master: code-rust - log

This commit is contained in:
RD 2022-04-14 05:01:08 +02:00
parent f192559eca
commit d0099eb7f9
2 changed files with 58 additions and 0 deletions

57
code/rust/src/core/log.rs Normal file
View File

@ -0,0 +1,57 @@
// ----------------------------------------------------------------
// IMPORTS
// ----------------------------------------------------------------
//
// ----------------------------------------------------------------
// METHODS log
// ----------------------------------------------------------------
/// Prints an info message
#[macro_export]
macro_rules! log_info{
($text:expr $(, $args:expr)* $(,)?)=>{
print!("[\x1b[94;1mINFO\x1b[0m] ");
println!($text$(, $args )*);
}
}
/// Prints a debug message
#[macro_export]
macro_rules! log_debug{
($text:expr $(, $args:expr)* $(,)?)=>{
print!("[\x1b[96;1mDEBUG\x1b[95;0m] ");
println!($text$(, $args )*);
}
}
#[allow(unused_imports)]
pub(crate) use log_debug;
// pub(crate) use log_debug;
/// Prints a warning message
#[macro_export]
macro_rules! log_warn{
($text:expr $(, $args:expr)* $(,)?)=>{
print!("[\x1b[93;1mWARNING\x1b[0m] ");
println!($text$(, $args )*);
}
}
/// Prints an error message
#[macro_export]
macro_rules! log_error{
($text:expr $(, $args:expr)* $(,)?)=>{
print!("[\x1b[91;1mERROR\x1b[0m] ");
println!($text$(, $args )*);
}
}
/// Prints a fatal error message + crashes
#[macro_export]
macro_rules! log_fatal{
($text:expr $(, $args:expr)* $(,)?)=>{
panic!("[\x1b[91;1mFATAL\x1b[0m] {}", format!($text$(, $args )*));
}
}

View File

@ -1 +1,2 @@
pub mod log;
pub mod utils;