From 9361acadcba3a8fd55f21ec379d39d651a3d3e49 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 19 Apr 2024 20:48:47 -0700 Subject: [PATCH] add debug log level macros. Signed-off-by: Jason Volk --- src/utils/debug.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/utils/mod.rs | 1 + 2 files changed, 42 insertions(+) create mode 100644 src/utils/debug.rs diff --git a/src/utils/debug.rs b/src/utils/debug.rs new file mode 100644 index 00000000..6c1093a0 --- /dev/null +++ b/src/utils/debug.rs @@ -0,0 +1,41 @@ +/// Log message at the ERROR level in debug-mode (when debug-assertions are +/// enabled). In release mode it becomes DEBUG level, and possibly subject to +/// elision. +#[macro_export] +macro_rules! debug_error { + ( $($x:tt)+ ) => { + if cfg!(debug_assertions) { + error!( $($x)+ ); + } else { + debug!( $($x)+ ); + } + } +} + +/// Log message at the WARN level in debug-mode (when debug-assertions are +/// enabled). In release mode it becomes DEBUG level, and possibly subject to +/// elision. +#[macro_export] +macro_rules! debug_warn { + ( $($x:tt)+ ) => { + if cfg!(debug_assertions) { + warn!( $($x)+ ); + } else { + debug!( $($x)+ ); + } + } +} + +/// Log message at the INFO level in debug-mode (when debug-assertions are +/// enabled). In release mode it becomes DEBUG level, and possibly subject to +/// elision. +#[macro_export] +macro_rules! debug_info { + ( $($x:tt)+ ) => { + if cfg!(debug_assertions) { + info!( $($x)+ ); + } else { + debug!( $($x)+ ); + } + } +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 225c2200..248ff144 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod debug; pub(crate) mod error; use std::{