From aef77bd3385b082c24da203c5748f9cd83eb2db4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 23 Apr 2024 11:15:29 -0700 Subject: [PATCH] add release_log_level feature to simulate release logs in debug mode. Signed-off-by: Jason Volk --- Cargo.toml | 3 +++ src/utils/debug.rs | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c87ce215..fb2dd1c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -377,6 +377,9 @@ hot_reload = ["dep:hot-lib-reloader"] hardened_malloc = ["hardened_malloc-rs"] +# developer feature useful only in debug builds. +release_log_level = [] + # client/server interopability hacks # ## element has various non-spec compliant behaviour diff --git a/src/utils/debug.rs b/src/utils/debug.rs index 32a8cf3f..119a92ff 100644 --- a/src/utils/debug.rs +++ b/src/utils/debug.rs @@ -1,9 +1,12 @@ /// Log event at given level in debug-mode (when debug-assertions are enabled). -/// In release mode it becomes DEBUG level, and possibly subject to elision. +/// In release-mode it becomes DEBUG level, and possibly subject to elision. +/// +/// Release-mode can be simulated in debug-mode builds by enabling the feature +/// 'release_log_level'. #[macro_export] macro_rules! debug_event { ( $level:expr, $($x:tt)+ ) => { - if cfg!(debug_assertions) { + if cfg!(debug_assertions) && cfg!(not(feature = "release_log_level")) { tracing::event!( $level, $($x)+ ); } else { tracing::debug!( $($x)+ ); @@ -12,7 +15,7 @@ macro_rules! debug_event { } /// 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 +/// enabled). In release-mode it becomes DEBUG level, and possibly subject to /// elision. #[macro_export] macro_rules! debug_error { @@ -22,7 +25,7 @@ macro_rules! debug_error { } /// 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 +/// enabled). In release-mode it becomes DEBUG level, and possibly subject to /// elision. #[macro_export] macro_rules! debug_warn { @@ -32,7 +35,7 @@ macro_rules! debug_warn { } /// 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 +/// enabled). In release-mode it becomes DEBUG level, and possibly subject to /// elision. #[macro_export] macro_rules! debug_info {