Skip to content

Logging improvements, second try #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::slice;

use ngx::core::{Pool, Status};
use ngx::ffi::{
nginx_version, ngx_atoi, ngx_command_t, ngx_conf_log_error, ngx_conf_t, ngx_connection_t, ngx_event_free_peer_pt,
nginx_version, ngx_atoi, ngx_command_t, ngx_conf_t, ngx_connection_t, ngx_event_free_peer_pt,
ngx_event_get_peer_pt, ngx_http_module_t, ngx_http_upstream_init_peer_pt, ngx_http_upstream_init_pt,
ngx_http_upstream_init_round_robin, ngx_http_upstream_module, ngx_http_upstream_srv_conf_t, ngx_http_upstream_t,
ngx_int_t, ngx_module_t, ngx_peer_connection_t, ngx_str_t, ngx_uint_t, NGX_CONF_NOARGS, NGX_CONF_TAKE1,
Expand All @@ -24,8 +24,10 @@ use ngx::http::{
ngx_http_conf_get_module_srv_conf, ngx_http_conf_upstream_srv_conf_immutable,
ngx_http_conf_upstream_srv_conf_mutable, HTTPModule, Merge, MergeConfigError, Request,
};
use ngx::log::DebugMask;
use ngx::{http_upstream_init_peer_pt, ngx_log_debug_http, ngx_log_debug_mask, ngx_null_command, ngx_string};
use ngx::{
http_upstream_init_peer_pt, ngx_conf_log_error, ngx_log_debug_http, ngx_log_debug_mask, ngx_null_command,
ngx_string,
};

#[derive(Clone, Copy, Debug)]
#[repr(C)]
Expand Down Expand Up @@ -243,12 +245,7 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(
let maybe_conf: Option<*mut SrvConfig> =
ngx_http_conf_upstream_srv_conf_mutable(us, &*addr_of!(ngx_http_upstream_custom_module));
if maybe_conf.is_none() {
ngx_conf_log_error(
NGX_LOG_EMERG as usize,
cf,
0,
"CUSTOM UPSTREAM no upstream srv_conf".as_bytes().as_ptr() as *const c_char,
);
ngx_conf_log_error!(NGX_LOG_EMERG, cf, "CUSTOM UPSTREAM no upstream srv_conf");
return isize::from(Status::NGX_ERROR);
}
let hccf = maybe_conf.unwrap();
Expand All @@ -259,12 +256,7 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(

let init_upstream_ptr = (*hccf).original_init_upstream.unwrap();
if init_upstream_ptr(cf, us) != Status::NGX_OK.into() {
ngx_conf_log_error(
NGX_LOG_EMERG as usize,
cf,
0,
"CUSTOM UPSTREAM failed calling init_upstream".as_bytes().as_ptr() as *const c_char,
);
ngx_conf_log_error!(NGX_LOG_EMERG, cf, "CUSTOM UPSTREAM failed calling init_upstream");
return isize::from(Status::NGX_ERROR);
}

Expand All @@ -291,13 +283,12 @@ unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
let value: &[ngx_str_t] = slice::from_raw_parts((*(*cf).args).elts as *const ngx_str_t, (*(*cf).args).nelts);
let n = ngx_atoi(value[1].data, value[1].len);
if n == (NGX_ERROR as isize) || n == 0 {
ngx_conf_log_error(
NGX_LOG_EMERG as usize,
ngx_conf_log_error!(
NGX_LOG_EMERG,
cf,
0,
"invalid value \"%V\" in \"%V\" directive".as_bytes().as_ptr() as *const c_char,
"invalid value \"{}\" in \"{}\" directive",
value[1],
&(*cmd).name,
&(*cmd).name
);
return usize::MAX as *mut c_char;
}
Expand Down Expand Up @@ -335,13 +326,10 @@ impl HTTPModule for Module {
let mut pool = Pool::from_ngx_pool((*cf).pool);
let conf = pool.alloc_type::<SrvConfig>();
if conf.is_null() {
ngx_conf_log_error(
NGX_LOG_EMERG as usize,
ngx_conf_log_error!(
NGX_LOG_EMERG,
cf,
0,
"CUSTOM UPSTREAM could not allocate memory for config"
.as_bytes()
.as_ptr() as *const c_char,
);
return std::ptr::null_mut();
}
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ pub mod http;
/// The log module.
///
/// This module provides an interface into the NGINX logger framework.
///
/// This module is temporally available only with `std` feature.
#[cfg(feature = "std")]
pub mod log;

/// Define modules exported by this library.
Expand Down
Loading
Loading