diff --git a/code/rust/src/core/log.rs b/code/rust/src/core/log.rs new file mode 100644 index 0000000..125fcde --- /dev/null +++ b/code/rust/src/core/log.rs @@ -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 )*)); + } +} diff --git a/code/rust/src/core/mod.rs b/code/rust/src/core/mod.rs index b5614dd..7cc1ec7 100644 --- a/code/rust/src/core/mod.rs +++ b/code/rust/src/core/mod.rs @@ -1 +1,2 @@ +pub mod log; pub mod utils;