@@ -13,31 +13,43 @@ use the_log_crate;
1313
1414pub ( crate ) use the_log_crate:: { error, info, warn} ;
1515
16- cfg_if :: cfg_if! {
17- if # [ cfg ( all ( not ( debug_assertions ) , not ( feature = "hot_log" ) ) ) ] {
18- // If it is release build and the feature "hot_log" is not enabled,
19- // then we define verbose logs as no-op in release build.
16+ /// Whether logs of DEBUG and TRACE levels are enabled.
17+ /// In debug build, they are always enabled.
18+ /// In release build, they are not enabled unless the "hot_log" Cargo feature is enabled.
19+ pub ( crate ) const HOT_LOG_ENABLED : bool = cfg ! ( any ( not ( debug_assertions ) , feature = "hot_log" ) ) ;
2020
21- /// The `log::debug!` macro is disabled in release build.
22- /// Use the "hot_log" feature to enable.
23- macro_rules! debug {
24- ( $( $arg: tt) +) => { }
21+ /// A wrapper of the `debug!` macro in the `log` crate.
22+ /// Does nothing if [`HOT_LOG_ENABLED`] is false.
23+ macro_rules! debug {
24+ ( target: $target: expr, $( $arg: tt) +) => {
25+ if $crate:: util:: log:: HOT_LOG_ENABLED {
26+ the_log_crate:: debug!( target: $target, $( $arg) +)
2527 }
26-
27- /// The `log::trace!` macro is disabled in release build.
28- /// Use the "hot_log" feature to enable.
29- macro_rules! trace {
30- ( $( $arg: tt) +) => { }
28+ } ;
29+ ( $( $arg: tt) +) => {
30+ if $crate:: util:: log:: HOT_LOG_ENABLED {
31+ the_log_crate:: debug!( $( $arg) +)
3132 }
33+ }
34+ }
3235
33- // By default, a macro has no path-based scope.
34- // The following allows other modules to access the macros with `crate::util::log::debug`
35- // and `crate::util::log::trace`.
36- pub ( crate ) use debug;
37- pub ( crate ) use trace;
38-
39- } else {
40- // Otherwise simply import the macros from the `log` crate.
41- pub ( crate ) use the_log_crate:: { debug, trace} ;
36+ /// A wrapper of the `trace!` macro in the `log` crate.
37+ /// Does nothing if [`HOT_LOG_ENABLED`] is false.
38+ macro_rules! trace {
39+ ( target: $target: expr, $( $arg: tt) +) => {
40+ if $crate:: util:: log:: HOT_LOG_ENABLED {
41+ the_log_crate:: trace!( target: $target, $( $arg) +)
42+ }
43+ } ;
44+ ( $( $arg: tt) +) => {
45+ if $crate:: util:: log:: HOT_LOG_ENABLED {
46+ the_log_crate:: trace!( $( $arg) +)
47+ }
4248 }
4349}
50+
51+ // By default, a macro has no path-based scope.
52+ // The following allows other modules to access the macros with `crate::util::log::debug`
53+ // and `crate::util::log::trace`.
54+ pub ( crate ) use debug;
55+ pub ( crate ) use trace;
0 commit comments