From 5be019c374eba9db65beb23f2445f3838dcaf43f Mon Sep 17 00:00:00 2001 From: Matthew Yacobucci Date: Wed, 19 Jul 2023 11:02:57 -0600 Subject: [PATCH 1/5] feat: Add debug log mask support NGINX supports multiple debug masks to customize logging. We use Rust's type system to represent these as an enum and ease a developers usage. They can call the ngx_log_debug_mask with any of the supported enum elements. To aid in keeping in sync with NGINX primitives a unit test will fail when the current FIRST and LAST log masks do not align any longer. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/log.rs | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 160 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25ee386..a69aae9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -456,7 +456,7 @@ dependencies = [ [[package]] name = "ngx" -version = "0.3.0-beta" +version = "0.4.0-beta" dependencies = [ "nginx-sys", ] diff --git a/Cargo.toml b/Cargo.toml index 6eac1e0..6fed388 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ [package] name = "ngx" -version = "0.3.0-beta" +version = "0.4.0-beta" edition = "2021" autoexamples = false categories = ["api-bindings", "network-programming"] diff --git a/src/log.rs b/src/log.rs index 37d4ac4..7e3930b 100644 --- a/src/log.rs +++ b/src/log.rs @@ -1,3 +1,27 @@ +// Utility function to provide typed checking of the mask's field state. +#[inline(always)] +fn check_mask(mask: DebugMasks, log_level: usize) -> bool { + let mask_bits: u32 = mask.into(); + if log_level & mask_bits as usize == 0 { + return false; + } + true +} + +// Internal macro, provided to reduce code duplication. +// +// Expects an ngx_log_t and message format template. +macro_rules! _ngx_log_debug_internal { + ( $log:expr, $($arg:tt)* ) => { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } + } +} + /// Write to logger at a specified level. /// /// See [Logging](https://nginx.org/en/docs/dev/development_guide.html#logging) @@ -7,12 +31,7 @@ macro_rules! ngx_log_debug { ( $log:expr, $($arg:tt)* ) => { let log_level = unsafe { (*$log).log_level }; if log_level != 0 { - let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; - let fmt = ::std::ffi::CString::new("%s").unwrap(); - let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); - unsafe { - $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); - } + $crate::_ngx_log_debug_internal!($log, $($arg)*); } } } @@ -27,3 +46,136 @@ macro_rules! ngx_log_debug_http { $crate::ngx_log_debug!(log, $($arg)*); } } + +/// Debug masks for use with ngx_log_debug_mask, these represent the only accepted values for the +/// mask. +#[derive(Debug)] +pub enum DebugMasks { + /// Aligns to the NGX_LOG_DEBUG_CORE mask. + Core, + /// Aligns to the NGX_LOG_DEBUG_ALLOC mask. + Alloc, + /// Aligns to the NGX_LOG_DEBUG_MUTEX mask. + Mutex, + /// Aligns to the NGX_LOG_DEBUG_EVENT mask. + Event, + /// Aligns to the NGX_LOG_DEBUG_HTTP mask. + Http, + /// Aligns to the NGX_LOG_DEBUG_MAIL mask. + Mail, + /// Aligns to the NGX_LOG_DEBUG_STREAM mask. + Stream, +} + +impl TryFrom for DebugMasks { + type Error = u32; + + fn try_from(value: u32) -> Result { + match value { + crate::ffi::NGX_LOG_DEBUG_CORE => Ok(DebugMasks::Core), + crate::ffi::NGX_LOG_DEBUG_ALLOC => Ok(DebugMasks::Alloc), + crate::ffi::NGX_LOG_DEBUG_MUTEX => Ok(DebugMasks::Mutex), + crate::ffi::NGX_LOG_DEBUG_EVENT => Ok(DebugMasks::Event), + crate::ffi::NGX_LOG_DEBUG_HTTP => Ok(DebugMasks::Http), + crate::ffi::NGX_LOG_DEBUG_MAIL => Ok(DebugMasks::Mail), + crate::ffi::NGX_LOG_DEBUG_STREAM => Ok(DebugMasks::Stream), + _ => Err(0), + } + } +} + +impl From for u32 { + fn from(value: DebugMasks) -> Self { + match value { + DebugMasks::Core => crate::ffi::NGX_LOG_DEBUG_CORE, + DebugMasks::Alloc => crate::ffi::NGX_LOG_DEBUG_ALLOC, + DebugMasks::Mutex => crate::ffi::NGX_LOG_DEBUG_MUTEX, + DebugMasks::Event => crate::ffi::NGX_LOG_DEBUG_EVENT, + DebugMasks::Http => crate::ffi::NGX_LOG_DEBUG_HTTP, + DebugMasks::Mail => crate::ffi::NGX_LOG_DEBUG_MAIL, + DebugMasks::Stream => crate::ffi::NGX_LOG_DEBUG_STREAM, + } + } +} + +/// Log with appropriate debug mask. +/// +/// When the request logger is available `ngx_log_debug_http` can be used for `NGX_LOG_DEBUG_HTTP` masks. +/// This macro is useful when other masks are necessary or when the request logger is not +/// conveniently accessible. +/// +/// See https://nginx.org/en/docs/dev/development_guide.html#logging for details and available +/// masks. +#[macro_export] +macro_rules! ngx_log_debug_mask { + ( DebugMasks::Core, $log:expr, $($arg:tt)* ) => ({ + let log_level = unsafe { (*$log).log_level }; + if check_mask(DebugMasks::Core, log_level) { + $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + } + }); + ( DebugMasks::Alloc, $log:expr, $($arg:tt)* ) => ({ + let log_level = unsafe { (*$log).log_level }; + if check_mask(DebugMasks::Alloc, log_level) { + $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + } + }); + ( DebugMasks::Mutex, $log:expr, $($arg:tt)* ) => ({ + let log_level = unsafe { (*$log).log_level }; + if check_mask(DebugMasks::Mutex, log_level) { + $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + } + }); + ( DebugMasks::Event, $log:expr, $($arg:tt)* ) => ({ + let log_level = unsafe { (*$log).log_level }; + if check_mask(DebugMasks::Event, log_level) { + $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + } + }); + ( DebugMasks::Http, $log:expr, $($arg:tt)* ) => ({ + let log_level = unsafe { (*$log).log_level }; + if check_mask(DebugMasks::Http, log_level) { + $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + } + }); + ( DebugMasks::Mail, $log:expr, $($arg:tt)* ) => ({ + let log_level = unsafe { (*$log).log_level }; + if check_mask(DebugMasks::Mail, log_level) { + $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + } + }); + ( DebugMasks::Stream, $log:expr, $($arg:tt)* ) => ({ + let log_level = unsafe { (*$log).log_level }; + if check_mask(DebugMasks::Stream, log_level) { + $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + } + }); +} + +#[cfg(test)] +mod tests { + + use super::*; + + #[test] + fn test_mask_lower_bound() { + assert!(>::into(DebugMasks::Core) == crate::ffi::NGX_LOG_DEBUG_FIRST); + } + #[test] + fn test_mask_upper_bound() { + assert!(>::into(DebugMasks::Stream) == crate::ffi::NGX_LOG_DEBUG_LAST); + } + #[test] + fn test_check_mask() { + struct MockLog { + log_level: usize, + } + let mock = MockLog { log_level: 16 }; + + let mut r = check_mask(DebugMasks::Core, mock.log_level); + assert!(r == true); + + r = check_mask(DebugMasks::Alloc, mock.log_level); + assert!(r == false); + } +} From 71c092ef9a04aa371ea4eca3b7b0137cd807aa28 Mon Sep 17 00:00:00 2001 From: Matthew Yacobucci Date: Wed, 19 Jul 2023 14:41:47 -0600 Subject: [PATCH 2/5] Code review: singular noun enums --- src/log.rs | 74 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/log.rs b/src/log.rs index 7e3930b..14edb5d 100644 --- a/src/log.rs +++ b/src/log.rs @@ -1,6 +1,6 @@ // Utility function to provide typed checking of the mask's field state. #[inline(always)] -fn check_mask(mask: DebugMasks, log_level: usize) -> bool { +fn check_mask(mask: DebugMask, log_level: usize) -> bool { let mask_bits: u32 = mask.into(); if log_level & mask_bits as usize == 0 { return false; @@ -50,7 +50,7 @@ macro_rules! ngx_log_debug_http { /// Debug masks for use with ngx_log_debug_mask, these represent the only accepted values for the /// mask. #[derive(Debug)] -pub enum DebugMasks { +pub enum DebugMask { /// Aligns to the NGX_LOG_DEBUG_CORE mask. Core, /// Aligns to the NGX_LOG_DEBUG_ALLOC mask. @@ -67,33 +67,33 @@ pub enum DebugMasks { Stream, } -impl TryFrom for DebugMasks { +impl TryFrom for DebugMask { type Error = u32; fn try_from(value: u32) -> Result { match value { - crate::ffi::NGX_LOG_DEBUG_CORE => Ok(DebugMasks::Core), - crate::ffi::NGX_LOG_DEBUG_ALLOC => Ok(DebugMasks::Alloc), - crate::ffi::NGX_LOG_DEBUG_MUTEX => Ok(DebugMasks::Mutex), - crate::ffi::NGX_LOG_DEBUG_EVENT => Ok(DebugMasks::Event), - crate::ffi::NGX_LOG_DEBUG_HTTP => Ok(DebugMasks::Http), - crate::ffi::NGX_LOG_DEBUG_MAIL => Ok(DebugMasks::Mail), - crate::ffi::NGX_LOG_DEBUG_STREAM => Ok(DebugMasks::Stream), + crate::ffi::NGX_LOG_DEBUG_CORE => Ok(DebugMask::Core), + crate::ffi::NGX_LOG_DEBUG_ALLOC => Ok(DebugMask::Alloc), + crate::ffi::NGX_LOG_DEBUG_MUTEX => Ok(DebugMask::Mutex), + crate::ffi::NGX_LOG_DEBUG_EVENT => Ok(DebugMask::Event), + crate::ffi::NGX_LOG_DEBUG_HTTP => Ok(DebugMask::Http), + crate::ffi::NGX_LOG_DEBUG_MAIL => Ok(DebugMask::Mail), + crate::ffi::NGX_LOG_DEBUG_STREAM => Ok(DebugMask::Stream), _ => Err(0), } } } -impl From for u32 { - fn from(value: DebugMasks) -> Self { +impl From for u32 { + fn from(value: DebugMask) -> Self { match value { - DebugMasks::Core => crate::ffi::NGX_LOG_DEBUG_CORE, - DebugMasks::Alloc => crate::ffi::NGX_LOG_DEBUG_ALLOC, - DebugMasks::Mutex => crate::ffi::NGX_LOG_DEBUG_MUTEX, - DebugMasks::Event => crate::ffi::NGX_LOG_DEBUG_EVENT, - DebugMasks::Http => crate::ffi::NGX_LOG_DEBUG_HTTP, - DebugMasks::Mail => crate::ffi::NGX_LOG_DEBUG_MAIL, - DebugMasks::Stream => crate::ffi::NGX_LOG_DEBUG_STREAM, + DebugMask::Core => crate::ffi::NGX_LOG_DEBUG_CORE, + DebugMask::Alloc => crate::ffi::NGX_LOG_DEBUG_ALLOC, + DebugMask::Mutex => crate::ffi::NGX_LOG_DEBUG_MUTEX, + DebugMask::Event => crate::ffi::NGX_LOG_DEBUG_EVENT, + DebugMask::Http => crate::ffi::NGX_LOG_DEBUG_HTTP, + DebugMask::Mail => crate::ffi::NGX_LOG_DEBUG_MAIL, + DebugMask::Stream => crate::ffi::NGX_LOG_DEBUG_STREAM, } } } @@ -108,45 +108,45 @@ impl From for u32 { /// masks. #[macro_export] macro_rules! ngx_log_debug_mask { - ( DebugMasks::Core, $log:expr, $($arg:tt)* ) => ({ + ( DebugMask::Core, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMasks::Core, log_level) { + if check_mask(DebugMask::Core, log_level) { $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); } }); - ( DebugMasks::Alloc, $log:expr, $($arg:tt)* ) => ({ + ( DebugMask::Alloc, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMasks::Alloc, log_level) { + if check_mask(DebugMask::Alloc, log_level) { $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); } }); - ( DebugMasks::Mutex, $log:expr, $($arg:tt)* ) => ({ + ( DebugMask::Mutex, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMasks::Mutex, log_level) { + if check_mask(DebugMask::Mutex, log_level) { $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); } }); - ( DebugMasks::Event, $log:expr, $($arg:tt)* ) => ({ + ( DebugMask::Event, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMasks::Event, log_level) { + if check_mask(DebugMask::Event, log_level) { $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); } }); - ( DebugMasks::Http, $log:expr, $($arg:tt)* ) => ({ + ( DebugMask::Http, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMasks::Http, log_level) { + if check_mask(DebugMask::Http, log_level) { $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); } }); - ( DebugMasks::Mail, $log:expr, $($arg:tt)* ) => ({ + ( DebugMask::Mail, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMasks::Mail, log_level) { + if check_mask(DebugMask::Mail, log_level) { $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); } }); - ( DebugMasks::Stream, $log:expr, $($arg:tt)* ) => ({ + ( DebugMask::Stream, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMasks::Stream, log_level) { + if check_mask(DebugMask::Stream, log_level) { $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); } }); @@ -159,11 +159,11 @@ mod tests { #[test] fn test_mask_lower_bound() { - assert!(>::into(DebugMasks::Core) == crate::ffi::NGX_LOG_DEBUG_FIRST); + assert!(>::into(DebugMask::Core) == crate::ffi::NGX_LOG_DEBUG_FIRST); } #[test] fn test_mask_upper_bound() { - assert!(>::into(DebugMasks::Stream) == crate::ffi::NGX_LOG_DEBUG_LAST); + assert!(>::into(DebugMask::Stream) == crate::ffi::NGX_LOG_DEBUG_LAST); } #[test] fn test_check_mask() { @@ -172,10 +172,10 @@ mod tests { } let mock = MockLog { log_level: 16 }; - let mut r = check_mask(DebugMasks::Core, mock.log_level); + let mut r = check_mask(DebugMask::Core, mock.log_level); assert!(r == true); - r = check_mask(DebugMasks::Alloc, mock.log_level); + r = check_mask(DebugMask::Alloc, mock.log_level); assert!(r == false); } } From 455a1ec0151d241178197b5826346f6fac5be11b Mon Sep 17 00:00:00 2001 From: Matthew Yacobucci Date: Thu, 20 Jul 2023 09:51:08 -0600 Subject: [PATCH 3/5] Code review notes - Prefer "///" comments - Reword ngx_log_debug_mask docs --- src/log.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/log.rs b/src/log.rs index 14edb5d..f91ce06 100644 --- a/src/log.rs +++ b/src/log.rs @@ -1,4 +1,4 @@ -// Utility function to provide typed checking of the mask's field state. +/// Utility function to provide typed checking of the mask's field state. #[inline(always)] fn check_mask(mask: DebugMask, log_level: usize) -> bool { let mask_bits: u32 = mask.into(); @@ -8,9 +8,9 @@ fn check_mask(mask: DebugMask, log_level: usize) -> bool { true } -// Internal macro, provided to reduce code duplication. -// -// Expects an ngx_log_t and message format template. +/// Internal macro, provided to reduce code duplication. +/// +/// Expects an ngx_log_t and message format template. macro_rules! _ngx_log_debug_internal { ( $log:expr, $($arg:tt)* ) => { let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; @@ -98,11 +98,11 @@ impl From for u32 { } } -/// Log with appropriate debug mask. +/// Log with requested debug mask. /// -/// When the request logger is available `ngx_log_debug_http` can be used for `NGX_LOG_DEBUG_HTTP` masks. -/// This macro is useful when other masks are necessary or when the request logger is not -/// conveniently accessible. +/// **NOTE:** This macro supports `DebugMask::Http` (`NGX_LOG_DEBUG_HTTP`), however, if you have +/// access to a Request object via an http handler it can be more convenient and readable to use the +/// `ngx_log_debug_http` macro instead. /// /// See https://nginx.org/en/docs/dev/development_guide.html#logging for details and available /// masks. From 1048500f96f9b26b9b718146fdac2ff5bf441a08 Mon Sep 17 00:00:00 2001 From: Matthew Yacobucci Date: Wed, 2 Aug 2023 12:02:08 -0600 Subject: [PATCH 4/5] Code review: no version increment --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a69aae9..25ee386 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -456,7 +456,7 @@ dependencies = [ [[package]] name = "ngx" -version = "0.4.0-beta" +version = "0.3.0-beta" dependencies = [ "nginx-sys", ] diff --git a/Cargo.toml b/Cargo.toml index 6fed388..6eac1e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ [package] name = "ngx" -version = "0.4.0-beta" +version = "0.3.0-beta" edition = "2021" autoexamples = false categories = ["api-bindings", "network-programming"] From 5d0d352aa1db0de053f7b2467012fa74a5b2657e Mon Sep 17 00:00:00 2001 From: Matthew Yacobucci Date: Thu, 3 Aug 2023 11:22:40 -0600 Subject: [PATCH 5/5] Code review notes Build showed private references aren't resolved during macro expansion. Removing some of the DRY code to solve build. --- src/log.rs | 86 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/src/log.rs b/src/log.rs index f91ce06..f302a92 100644 --- a/src/log.rs +++ b/src/log.rs @@ -1,6 +1,6 @@ /// Utility function to provide typed checking of the mask's field state. #[inline(always)] -fn check_mask(mask: DebugMask, log_level: usize) -> bool { +pub fn check_mask(mask: DebugMask, log_level: usize) -> bool { let mask_bits: u32 = mask.into(); if log_level & mask_bits as usize == 0 { return false; @@ -8,20 +8,6 @@ fn check_mask(mask: DebugMask, log_level: usize) -> bool { true } -/// Internal macro, provided to reduce code duplication. -/// -/// Expects an ngx_log_t and message format template. -macro_rules! _ngx_log_debug_internal { - ( $log:expr, $($arg:tt)* ) => { - let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; - let fmt = ::std::ffi::CString::new("%s").unwrap(); - let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); - unsafe { - $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); - } - } -} - /// Write to logger at a specified level. /// /// See [Logging](https://nginx.org/en/docs/dev/development_guide.html#logging) @@ -31,7 +17,12 @@ macro_rules! ngx_log_debug { ( $log:expr, $($arg:tt)* ) => { let log_level = unsafe { (*$log).log_level }; if log_level != 0 { - $crate::_ngx_log_debug_internal!($log, $($arg)*); + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } } } @@ -110,44 +101,79 @@ impl From for u32 { macro_rules! ngx_log_debug_mask { ( DebugMask::Core, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMask::Core, log_level) { - $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + if $crate::log::check_mask(DebugMask::Core, log_level) { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } }); ( DebugMask::Alloc, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMask::Alloc, log_level) { - $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + if $crate::log::check_mask(DebugMask::Alloc, log_level) { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } }); ( DebugMask::Mutex, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMask::Mutex, log_level) { - $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + if $crate::log::check_mask(DebugMask::Mutex, log_level) { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } }); ( DebugMask::Event, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMask::Event, log_level) { - $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + if $crate::log::check_mask(DebugMask::Event, log_level) { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } }); ( DebugMask::Http, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMask::Http, log_level) { - $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + if $crate::log::check_mask(DebugMask::Http, log_level) { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } }); ( DebugMask::Mail, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMask::Mail, log_level) { - $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + if $crate::log::check_mask(DebugMask::Mail, log_level) { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } }); ( DebugMask::Stream, $log:expr, $($arg:tt)* ) => ({ let log_level = unsafe { (*$log).log_level }; - if check_mask(DebugMask::Stream, log_level) { - $crate::_ngx_log_debug_internal!(log, $($arg:tt)*); + if $crate::log::check_mask(DebugMask::Stream, log_level) { + let level = $crate::ffi::NGX_LOG_DEBUG as $crate::ffi::ngx_uint_t; + let fmt = ::std::ffi::CString::new("%s").unwrap(); + let c_message = ::std::ffi::CString::new(format!($($arg)*)).unwrap(); + unsafe { + $crate::ffi::ngx_log_error_core(level, $log, 0, fmt.as_ptr(), c_message.as_ptr()); + } } }); }