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

[Question] Is it possible to disable logs before creating the Enforcer? #155

Open
mikyll opened this issue May 9, 2024 · 4 comments
Open

Comments

@mikyll
Copy link

mikyll commented May 9, 2024

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
@casbin-bot
Copy link
Member

@Edmond-J-A @rushitote @techoner

@hsluoyz
Copy link
Member

hsluoyz commented May 9, 2024

@mikyll why do you want to do this? Can't turn off after creation?

@mikyll
Copy link
Author

mikyll commented May 9, 2024

@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 🙂

@hsluoyz
Copy link
Member

hsluoyz commented May 9, 2024

@mikyll see how Go Casbin does this: https://github.com/casbin/casbin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

3 participants