Skip to content
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

chore: improve the core.log module #1093

Merged
merged 1 commit into from
Jan 28, 2020
Merged
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
33 changes: 9 additions & 24 deletions lua/apisix/core/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,22 @@ local log_levels = {
error = ngx.ERR,
warn = ngx.WARN,
notice = ngx.NOTICE,
info = ngx.INFO
info = ngx.INFO,
debug = ngx.DEBUG,
}


do
local cur_level

function _M.debug(...)
if not cur_level then
cur_level = ngx.config.subsystem == "http" and
require "ngx.errlog" .get_sys_filter_level()
end

if not DEBUG and cur_level and ngx_DEBUG > cur_level then
return
end

return ngx_log(ngx_DEBUG, ...)
end

end -- do


local cur_level = ngx.config.subsystem == "http" and
require "ngx.errlog" .get_sys_filter_level()
local do_nothing = function() end
setmetatable(_M, {__index = function(self, cmd)
local cur_level = ngx.config.subsystem == "http" and
require "ngx.errlog" .get_sys_filter_level()
local log_level = log_levels[cmd]

local method
if cur_level and log_levels[cmd] > cur_level then
method = function() end
if cur_level and (log_level > cur_level or
(log_level == ngx_DEBUG and not DEBUG))
then
method = do_nothing
else
method = function(...)
return ngx_log(log_level, ...)
Expand Down