44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
log_by_lua_block {
|
|
|
|
local utils = require "utils"
|
|
local logger = require "logger"
|
|
local datastore = require "datastore"
|
|
local plugins = require "plugins"
|
|
|
|
logger.log(ngx.INFO, "LOG", "Log phase started")
|
|
|
|
-- List all plugins
|
|
local list, err = plugins:list()
|
|
if not list then
|
|
logger.log(ngx.ERR, "LOG", "Can't list loaded plugins : " .. err)
|
|
list = {}
|
|
end
|
|
|
|
-- Call log method of plugins
|
|
for i, plugin in ipairs(list) do
|
|
local ret, plugin_lua = pcall(require, plugin.id .. "/" .. plugin.id)
|
|
if ret then
|
|
local plugin_obj = plugin_lua.new()
|
|
if plugin_obj.log ~= nil then
|
|
logger.log(ngx.INFO, "LOG", "Executing log() of " .. plugin.id)
|
|
local ok, err = plugin_obj:log()
|
|
if not ok then
|
|
logger.log(ngx.ERR, "LOG", "Error while calling log() on plugin " .. plugin.id .. " : " .. err)
|
|
else
|
|
logger.log(ngx.INFO, "LOG", "Return value from " .. plugin.id .. ".log() is : " .. err)
|
|
end
|
|
else
|
|
logger.log(ngx.INFO, "LOG", "log() method not found in " .. plugin.id .. ", skipped execution")
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Display reason at info level
|
|
local reason = utils.get_reason()
|
|
if reason then
|
|
logger.log(ngx.INFO, "LOG", "Client was denied with reason : " .. reason)
|
|
end
|
|
|
|
logger.log(ngx.INFO, "LOG", "Log phase ended")
|
|
|
|
} |