question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with pycasbin logging

See original GitHub issue

PyCasbin 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:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hsluoyzcommented, Feb 4, 2021

@rituperiwal sorry for the breaking change. We will fix it in next version: https://github.com/casbin/pycasbin/issues/119

1reaction
jessecoopercommented, Jan 21, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

casbin-django-orm-adapter - PyPI
If True , enables logging. False by default. CASBIN_ADAPTER. A string containing the adapter import path. Defaults to the django adapter shipped with...
Read more >
Python packages index - Page 389 | Snyk Advisor - Snyk
Python Packages Index, security: no known security issues · flask-pw3 · flask-pw3-1 · flask-pwa · flask-pybankid · flask-pycasbin · flask-pyco · flask-pyctuator ·...
Read more >
casbin/Lobby - Gitter
Hello, is it possible to add "field fitlers"? We want to use casbin for an API. "Alice is allowed to GET /api/user/12345 but...
Read more >
casbin - crates.io: Rust Package Registry
PyCasbin · Casbin. ... It doesn't control the access to a specific article or log. ... If you have any issues or feature...
Read more >
https://raw.githubusercontent.com/casbin/pycasbin/...
... autoloader error handling ([#275](https://github.com/casbin/pycasbin/issues/275)) ... (2022-06-22) ### Bug Fixes * Set the default log level to warning ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found