Skip to content

Commit

Permalink
chore: avoid creating noisy logs when debugging a service with many r…
Browse files Browse the repository at this point in the history
…outes (#101)
  • Loading branch information
spacewander committed Aug 18, 2021
1 parent c5a0798 commit d8fc176
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/resty/radixtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,17 @@ end


local ngx_log = ngx.log
local ngx_DEBUG = ngx.DEBUG
local ngx_INFO = ngx.INFO
local ngx_ERR = ngx.ERR
local function log_debug(...)
if cur_level and ngx_DEBUG > cur_level then
return
end

return ngx_log(ngx_DEBUG, ...)
end

local function log_info(...)
if cur_level and ngx_INFO > cur_level then
return
Expand Down Expand Up @@ -485,7 +494,7 @@ local function compare_param(req_path, route, opts)
end

local pat, names = fetch_pat(route.path_org)
log_info("pcre pat: ", pat)
log_debug("pcre pat: ", pat)
if #names == 0 then
return true
end
Expand Down Expand Up @@ -561,7 +570,6 @@ local function match_route_opts(route, opts, args)
end
end

log_info("hosts match: ", matched)
if not matched then
return false
end
Expand Down
2 changes: 2 additions & 0 deletions t/parameter.t
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ matched: []
=== TEST 7: /name/:name/foo (no cached parameter)
--- log_level: debug
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -239,6 +240,7 @@ pcre pat:
=== TEST 8: /:name/foo
--- log_level: debug
--- config
location /t {
content_by_lua_block {
Expand Down

0 comments on commit d8fc176

Please sign in to comment.