pycasbin / django-orm-adapter

Django ORM Adapter for PyCasbin
https://github.com/casbin/pycasbin
Apache License 2.0
30 stars 19 forks source link

CASBIN_LOG_ENABLED not working #19

Closed leohahn closed 1 year ago

leohahn commented 1 year ago

Adding

CASBIN_LOG_ENABLED = False

does not work. Looking into the code the setting is not passed to the constructor. That seems to be a bug right?

casbin-bot commented 1 year ago

@techoner @Nekotoxin

hsluoyz commented 1 year ago

@leohahn it's here:

https://github.com/pycasbin/django-orm-adapter/blob/9cc651366706058502da217a87f97f91fe3fcd6c/casbin_adapter/enforcer.py#L28

leohahn commented 1 year ago

Yes, but this variable is not used anywhere. I tried setting this to true but nothing changes for logging. Where is this variable used?

hsluoyz commented 1 year ago

@BustDot

BustDot commented 1 year ago

@leohahn You can control the log by setting logging config in settings.py. You can refer to django docs. Here is an example to log info and upper level message to console:

# settings.py
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "casbin_formatter": {
            "format": "{asctime} {message}",
            "style": "{",
        }
    },
    "handlers": {
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "formatter": "casbin_formatter",
        },
    },
    "loggers": {
        "casbin_adapter": {
            "handlers": ["console"],
            "level": "INFO",
        },
    },
}