From: Jason Ish Date: Mon, 16 Nov 2020 17:36:39 +0000 (-0600) Subject: rust/log: expand macros after checking log level X-Git-Tag: suricata-6.0.1~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=411a5d41c1e108fa183175a5869e3d1451f862cf;p=thirdparty%2Fsuricata.git rust/log: expand macros after checking log level Expand macros in the do_log macro after checking the log level instead of each log macro (ie: SCLogDebug) expanding the macros then passing off to do_log to have the log level check. Will eliminate any expense of expanding macros if this log level does not permit the given message to be logged. Redmine issue: https://redmine.openinfosecfoundation.org/issues/4114 --- diff --git a/rust/src/log.rs b/rust/src/log.rs index 90f8a27106..75e0a4b4a5 100644 --- a/rust/src/log.rs +++ b/rust/src/log.rs @@ -108,10 +108,9 @@ macro_rules!function { #[macro_export] macro_rules!do_log { - ($level:expr, $file:expr, $line:expr, $function:expr, $code:expr, - $($arg:tt)*) => { + ($level:expr, $code:expr, $($arg:tt)*) => { if $crate::log::get_log_level() >= $level as i32 { - $crate::log::sclog($level, $file, $line, $function, $code, + $crate::log::sclog($level, file!(), line!(), $crate::function!(), $code, &(format!($($arg)*))); } } @@ -120,36 +119,36 @@ macro_rules!do_log { #[macro_export] macro_rules!SCLogNotice { ($($arg:tt)*) => { - $crate::do_log!($crate::log::Level::Notice, file!(), line!(), $crate::function!(), 0, $($arg)*); + $crate::do_log!($crate::log::Level::Notice, 0, $($arg)*); } } #[macro_export] macro_rules!SCLogInfo { ($($arg:tt)*) => { - $crate::do_log!($crate::log::Level::Info, file!(), line!(), $crate::function!(), 0, $($arg)*); + $crate::do_log!($crate::log::Level::Info, 0, $($arg)*); } } #[macro_export] macro_rules!SCLogPerf { ($($arg:tt)*) => { - $crate::do_log!($crate::log::Level::Perf, file!(), line!(), $crate::function!(), 0, $($arg)*); + $crate::do_log!($crate::log::Level::Perf, 0, $($arg)*); } } #[macro_export] macro_rules!SCLogConfig { ($($arg:tt)*) => { - $crate::do_log!($crate::log::Level::Config, file!(), line!(), $crate::function!(), 0, $($arg)*); + $crate::do_log!($crate::log::Level::Config, 0, $($arg)*); } } #[macro_export] macro_rules!SCLogError { ($($arg:tt)*) => { - $crate::do_log!($crate::log::Level::Error, file!(), line!(), $crate::function!(), 0, $($arg)*); - } + $crate::do_log!($crate::log::Level::Error, 0, $($arg)*); + }; } // Debug mode: call C SCLogDebug @@ -157,7 +156,7 @@ macro_rules!SCLogError { #[macro_export] macro_rules!SCLogDebug { ($($arg:tt)*) => { - do_log!($crate::log::Level::Debug, file!(), line!(), $crate::function!(), 0, $($arg)*); + do_log!($crate::log::Level::Debug, 0, $($arg)*); } }