From 2371576619123734b42a1957548f67306e984d45 Mon Sep 17 00:00:00 2001 From: willmafh Date: Thu, 31 Aug 2023 19:07:24 +0800 Subject: [PATCH] log_by_lua* directives in stream level bugfix & add a corresponding test case --- src/ngx_stream_lua_module.c | 7 +++++++ t/075-logby.t | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/ngx_stream_lua_module.c b/src/ngx_stream_lua_module.c index 9cdfc5d3..6554ebf7 100644 --- a/src/ngx_stream_lua_module.c +++ b/src/ngx_stream_lua_module.c @@ -1002,6 +1002,13 @@ ngx_stream_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) conf->preread_chunkname = prev->preread_chunkname; } + if (conf->log_src.value.len == 0) { + conf->log_src = prev->log_src; + conf->log_handler = prev->log_handler; + conf->log_src_key = prev->log_src_key; + conf->log_chunkname = prev->log_chunkname; + } + return NGX_CONF_OK; } diff --git a/t/075-logby.t b/t/075-logby.t index c2366bdd..62ca9f8b 100644 --- a/t/075-logby.t +++ b/t/075-logby.t @@ -363,3 +363,17 @@ log handler ok --- no_error_log [error] + + + +=== TEST 21: log_by_lua in stream level +--- stream_config + log_by_lua_block { ngx.log(ngx.ERR, "Hello from log_by_lua stream level: ", ngx.var.protocol) } +--- stream_server_config + content_by_lua_block { + ngx.say('hello') + } +--- stream_response +hello +--- error_log +Hello from log_by_lua stream level: TCP