Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ production-ready | production-ready | beta-test | production-ready
- [Role manager](#role-manager)
- [Async Enforcer](#async-enforcer)
- [Benchmarks](#benchmarks)
- [Logging](#logging)
- [Examples](#examples)
- [Middlewares](#middlewares)
- [Our adopters](#our-adopters)
Expand Down Expand Up @@ -291,6 +292,10 @@ asyncio.run(main())

https://casbin.org/docs/benchmark

## Logging

pycasbin leverages the default Python logging mechanism. The pycasbin package makes a call to `logging.getLogger()` to set the logger. No special logging configuration is needed other than initializing the logger in the parent application. If no logging is initialized within the parent application, you will not see any log messages from pycasbin. At the same time, When you enable log in pycasbin, you can specify the logging configuration through the parameter `logging_config`. If no configuration is specified, it will use the [default log configuration](https://github.com/casbin/pycasbin/blob/c33cabfa0ac65cd09cf812a65e71794d64cb5132/casbin/util/log.py#L6C1-L6C1). For other pycasbin extensions, you can refer to the [Django logging docs](https://docs.djangoproject.com/en/4.2/topics/logging/) if you are a Django user. For other Python users, you should refer to the [Python logging docs](https://docs.python.org/3/library/logging.config.html) to configure the logger.

## Examples

Model | Model file | Policy file
Expand Down
4 changes: 2 additions & 2 deletions casbin/core_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CoreEnforcer:
auto_build_role_links = False
auto_notify_watcher = False

def __init__(self, model=None, adapter=None, enable_log=False):
def __init__(self, model=None, adapter=None, enable_log=False, logging_config: dict = None):
self.logger = logging.getLogger("casbin.enforcer")
if isinstance(model, str):
if isinstance(adapter, str):
Expand All @@ -70,7 +70,7 @@ def __init__(self, model=None, adapter=None, enable_log=False):
self.init_with_model_and_adapter(model, adapter)

if enable_log:
configure_logging()
configure_logging(logging_config)
else:
disabled_logging()

Expand Down
11 changes: 9 additions & 2 deletions casbin/fast_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
class FastEnforcer(Enforcer):
_cache_key_order: Sequence[int] = None

def __init__(self, model=None, adapter=None, enable_log=False, cache_key_order: Sequence[int] = None):
def __init__(
self,
model=None,
adapter=None,
enable_log=False,
logging_config: dict = None,
cache_key_order: Sequence[int] = None,
):
self._cache_key_order = cache_key_order
super().__init__(model, adapter, enable_log)
super().__init__(model, adapter, enable_log, logging_config)

def new_model(self, path="", text=""):
"""creates a model."""
Expand Down