[Question] Is it possible to disable logs before creating the Enforcer?
I'm using casbin in a Custom Kong plugin, and I'm getting these log entries when loading the model and policy:
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFOModel:
, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO[r.r]:, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO{RM = {}, key = "r", policy = {}, policyMap = {}, priorityIndex = -1, tokens = {"r_sub", "r_obj", "r_act"}, value = "sub, obj, act"}, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO[p.p]:, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO{RM = {}, key = "p", policy = {}, policyMap = {}, priorityIndex = -1, tokens = {"p_sub", "p_obj", "p_act"}, value = "sub, obj, act"}, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO[e.e]:, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO{RM = {}, key = "e", policy = {}, policyMap = {}, priorityIndex = -1, tokens = {}, value = "some(where (p_eft == allow))"}, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO[m.m]:, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO{RM = {}, key = "m", policy = {}, policyMap = {}, priorityIndex = -1, tokens = {}, value = "r_sub == p_sub && regexMatch(r_obj, p_obj) && regexMatch(r_act, p_act)"}, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFOPolicy:
, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFOp: sub, obj, act:, context: ngx.timer
2024/05/09 14:13:02 [notice] 2441#0: *4 [lua] Log.lua:29: info(): INFO{my-list-of-policies}, context: ngx.timer
Goal: I'd like to enable/disable these log messages, based on a plugin configuration parameter (conf.debug).
I see that there is a enableLog() method, but is there a way to disable logs before creating the enforcer itself?
My code is basically this:
local CustomHandler = {
NAME = "my-plugin",
PRIORITY = 1000,
VERSION = "0.1",
}
local casbin = require("casbin")
function CustomHandler:access(conf)
local enforcer = casbin:new(conf.model_path, conf.policy_path)
enforcer:enableLogs(conf.debug)
-- [...]
end
return CustomHandler
@Edmond-J-A @rushitote @techoner
@mikyll why do you want to do this? Can't turn off after creation?
@hsluoyz Since we have hundreds if not thousands of policy entries, I would like to make that logging entires configurable, in order to make it more readable. Moreover, in our plugin, the enforcer reloads the policies each time the plugin configuration changes, and that would add a lot of logging entries, making it harder to debug Kong-related issues
In short, it's just a matter of preference, so I'd just like to know if it's possible, and in case how 🙂
@mikyll see how Go Casbin does this: https://github.com/casbin/casbin
I forgot to update this issue 🙂
This was never an actual problem but rather a matter of preference. Most importantly, it can be addressed on Kong's side. The proper way to prevent Kong from showing these log entries is by adjusting the logging level to a higher setting. By default, Kong's log level is set to notice. Raising it to a higher level, such as warn, would prevent Casbin's INFO logs from being displayed.
Reference: Kong Docs | Logging Reference