Issue with pycasbin logging
See original GitHub issuePyCasbin currently sets up its own logger: https://github.com/casbin/pycasbin/tree/master/casbin/log
Since pycasbin is a supporting module to an application it should differ the logging setup to the application that would leverage the module. This is done by the module class setting self.logger = logging.getLogger()
to get the root logger.
Then when calls are made with self.logger.[method]([message])
it will either log as expected or if no logger is gotten then it just wont log as expected. Currently there is no way to override the default pycasbin log level because it is statically set and if you disable the logger you disable all log messages. There is also no good way to override the enforcer class logger since it is not class property.
https://github.com/casbin/pycasbin/blob/master/casbin/log/default_logger.py#L11 https://github.com/casbin/pycasbin/blob/master/casbin/core_enforcer.py#L1 https://github.com/casbin/pycasbin/blob/master/casbin/core_enforcer.py#L25 https://github.com/casbin/pycasbin/blob/master/casbin/core_enforcer.py#L289
The current behavior of pycasbin results in duplicate logs when the application sets up a logger of its own.
2020-10-13 15:54:01,688 - INFO - Request: isadmin, /api/v1/applications, GET ---> True
[2020-10-13 15:54:01,688] INFO in default_logger: Request: isadmin, /api/endpoint, GET ---> True
I will open a PR for these changes when I can unless someones gets to it before me.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
@rituperiwal sorry for the breaking change. We will fix it in next version: https://github.com/casbin/pycasbin/issues/119
I would make get_enforcer or validate access a decorator that uses caching. This is what I do with flask-authz: https://github.com/pycasbin/flask-authz/blob/master/flask_authz/casbin_enforcer.py#L54 at least this way you will only load it once per lambda. This way it caches the enforcer.
https://github.com/casbin/pycasbin/pull/80 has not yet been merged.