diff --git a/src/ngx_http_lua_kong_log.c b/src/ngx_http_lua_kong_log.c index 8ba12828..f0027d55 100644 --- a/src/ngx_http_lua_kong_log.c +++ b/src/ngx_http_lua_kong_log.c @@ -63,6 +63,11 @@ ngx_http_lua_kong_ffi_set_dynamic_log_level(int log_level, int timeout) return NGX_ERROR; } + /* adhere to nginx conventions */ + if (log_level == NGX_LOG_DEBUG) { + log_level = NGX_LOG_DEBUG_ALL; + } + g_dynamic_log_level = log_level; g_dynamic_log_level_timeout_at = (time_t)ngx_time() + (time_t)timeout; @@ -87,5 +92,11 @@ ngx_http_lua_kong_get_dynamic_log_level(ngx_uint_t current_log_level) int ngx_http_lua_kong_ffi_get_dynamic_log_level(int current_log_level) { - return ngx_http_lua_kong_get_dynamic_log_level(current_log_level); + int log_level = ngx_http_lua_kong_get_dynamic_log_level(current_log_level); + + if (log_level == NGX_LOG_DEBUG_ALL) { + log_level = NGX_LOG_DEBUG; + } + + return log_level; } diff --git a/t/008-log.t b/t/008-log.t index 98bc1003..9e80bd46 100644 --- a/t/008-log.t +++ b/t/008-log.t @@ -7,7 +7,7 @@ use Test::Nginx::Socket::Lua; #master_process_enabled(1); log_level('warn'); -plan tests => repeat_each() * (blocks() * 4) + 8; +plan tests => repeat_each() * (blocks() * 4) + 6; #no_diff(); #no_long_string(); @@ -938,3 +938,27 @@ GET /test ] --- no_log eval "you can't see me init_worker" + + +=== TEST 25: debug log level for nginx error.log +--- http_config + lua_package_path "../lua-resty-core/lib/?.lua;lualib/?.lua;;"; +--- config + location = /test_nginx_debug_log { + + error_log logs/error.log crit; + + content_by_lua_block { + local log = require("resty.kong.log") + log.set_log_level(ngx.DEBUG, 10) + assert(log.get_log_level(ngx.WARN) == ngx.DEBUG) + ngx.exit(403) + } + } +--- request +GET /test_nginx_debug_log +--- error_code: 403 +--- error_log eval +[ + qr/\[debug\] .*: .* http finalize request: 403, "\/test_nginx_debug_log\?" a:1, c:1/, +]