Skip to content

Commit

Permalink
fix(template): fix failure of starting if proxy_access_log is off
Browse files Browse the repository at this point in the history
  • Loading branch information
ADD-SP committed Oct 9, 2023
1 parent 71b6ea5 commit 6e4c25b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions kong/cmd/utils/prefix_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ local function compile_conf(kong_config, conf_template, template_env_inject)
-- computed config properties for templating
local compile_env = {
_escape = ">",
proxy_access_log_enabled = kong_config.proxy_access_log ~= "off",
pairs = pairs,
ipairs = ipairs,
tostring = tostring,
Expand Down
5 changes: 5 additions & 0 deletions kong/templates/nginx_kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ server {
# https://github.com/Kong/lua-kong-nginx-module#lua_kong_error_log_request_id
lua_kong_error_log_request_id $request_id;
> if proxy_access_log_enabled then
access_log ${{PROXY_ACCESS_LOG}} kong_log_format;
> else
access_log off;
> end
error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};
> if proxy_ssl_enabled then
Expand Down
10 changes: 10 additions & 0 deletions spec/01-unit/04-prefix_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ describe("NGINX conf compiler", function()
local nginx_conf = prefix_handler.compile_kong_stream_conf(conf)
assert.matches("access_log%slogs/access.log%sbasic;", nginx_conf)

local conf = assert(conf_loader(nil, {
proxy_access_log = "off",
stream_listen = "0.0.0.0:9100",
nginx_stream_tcp_nodelay = "on",
}))
local nginx_conf = prefix_handler.compile_kong_conf(conf)
assert.matches("access_log%soff;", nginx_conf)
local nginx_conf = prefix_handler.compile_kong_stream_conf(conf)
assert.matches("access_log%slogs/access.log%sbasic;", nginx_conf)

local conf = assert(conf_loader(nil, {
proxy_stream_access_log = "/dev/stdout custom",
stream_listen = "0.0.0.0:9100",
Expand Down

0 comments on commit 6e4c25b

Please sign in to comment.