Skip to content

Commit

Permalink
Update log filter
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed Mar 21, 2024
1 parent cf672ab commit 59a94bc
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions jls/net/http/filter/LogHttpFilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@ After adding this filter, any request containing the header *jls-logger-level* w
@pragma nostrip
]]

local logger = require('jls.lang.logger'):get(...)
local rootLogger = require('jls.lang.logger')

--- A LogHttpFilter class.
-- @type LogHttpFilter
return require('jls.lang.class').create('jls.net.http.HttpFilter', function(filter)

function filter:doFilter(exchange)
local ml = exchange:getRequest():getHeader('jls-logger-level')
if ml then
ml = logger:getClass().levelFromString(ml)
if ml then
local level = logger:getLevel()
if ml < level then
logger:setLevel(ml)
exchange:onClose():next(function()
logger:setLevel(level)
end)
end
end
local ll = exchange:getRequest():getHeader('jls-logger-level')
if ll then
local config = rootLogger:getConfig()
rootLogger:cleanConfig()
rootLogger:applyConfig(ll)
exchange:onClose():next(function()
rootLogger:cleanConfig()
rootLogger:applyConfig(config)
end)
end
end

Expand Down

0 comments on commit 59a94bc

Please sign in to comment.