]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Rust: add 'debug' feature
authorPierre Chifflier <chifflier@wzdftpd.net>
Tue, 6 Mar 2018 20:33:33 +0000 (21:33 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 7 Mar 2018 08:22:37 +0000 (09:22 +0100)
The 'debug' feature is enabled if suricata was configured with the
--enabled-debug' flag.
If enabled, the SCLogDebug format and calls the logging function as
usual. Otherwise, this macro is a no-op (similarly to the C code).

rust/Cargo.toml.in
rust/Makefile.am
rust/src/log.rs

index 1a0384cddc425e3d1cc3e871ab16b5e4923b2a82..9cd079f7a227615d3f3215b74a692b3988b92441 100644 (file)
@@ -12,6 +12,7 @@ debug = true
 lua = []
 experimental = ["ntp-parser"]
 strict = []
+debug = []
 
 [dependencies]
 nom = "~3.2.1"
index 776d86b77ab0144239c19137cdccc529db29fc03..6bc8a7b018c654c2d5441b57ce784af1d54815fc 100644 (file)
@@ -29,6 +29,10 @@ if HAVE_RUST_EXTERNAL
 RUST_FEATURES +=       experimental
 endif
 
+if DEBUG
+RUST_FEATURES +=       debug
+endif
+
 all-local:
 if HAVE_PYTHON
        cd $(top_srcdir)/rust && \
index 018888ca5f5a99e3b5cc13a726802c9be0652a9e..bdc4cc0e09eda40e8df7b98fee9266dc8e63a381 100644 (file)
@@ -114,6 +114,8 @@ macro_rules!SCLogConfig {
     }
 }
 
+// Debug mode: call C SCLogDebug
+#[cfg(feature = "debug")]
 #[macro_export]
 macro_rules!SCLogDebug {
     ($($arg:tt)*) => {
@@ -121,6 +123,15 @@ macro_rules!SCLogDebug {
     }
 }
 
+// Release mode: ignore arguments
+// Use a reference to avoid moving values.
+#[cfg(not(feature = "debug"))]
+#[macro_export]
+macro_rules!SCLogDebug {
+    ($last:expr) => { let _ = &$last; let _ = Level::Debug; };
+    ($one:expr, $($arg:tt)*) => { let _ = &$one; SCLogDebug!($($arg)*); };
+}
+
 #[no_mangle]
 pub extern "C" fn rs_log_set_level(level: i32) {
     unsafe {