From 61f842f8d0167a5921c3a02dfac91506b5aaf8e7 Mon Sep 17 00:00:00 2001 From: LeTeddy <15123120+working-on-it@user.noreply.gitee.com> Date: Sat, 15 Mar 2025 23:13:14 +0800 Subject: [PATCH 1/2] feat: modify logging usage desc for casbin and pyCasbin --- docs/LogError.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/LogError.mdx b/docs/LogError.mdx index a582dc06..7c468431 100644 --- a/docs/LogError.mdx +++ b/docs/LogError.mdx @@ -14,12 +14,12 @@ Casbin uses the built-in `log` to print logs to the console by default, like: 2017/07/15 19:43:56 [Request: alice, data1, read ---> true] ``` -Logging is not enabled by default. You can toggle it via `Enforcer.EnableLog()` or the last parameter of `NewEnforcer()`. +Logging is not enabled by default. :::note -We already support logging the model, enforce request, role, and policy in Golang. You can define your own log for logging Casbin. -If you are using Python, 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, 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. +For Golang: We already support logging the model, enforce request, role, and policy in Golang. You can define your own log for logging Casbin.You can toggle it via `Enforcer.EnableLog()` or the last parameter of `NewEnforcer()`.  +For Python: 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. ::: ### Use different loggers for different enforcers From 980664ce945816f6d9dc876ed808eed65e6ed4c5 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sat, 15 Mar 2025 23:29:53 +0800 Subject: [PATCH 2/2] Update LogError.mdx --- docs/LogError.mdx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/LogError.mdx b/docs/LogError.mdx index 7c468431..3b3df77c 100644 --- a/docs/LogError.mdx +++ b/docs/LogError.mdx @@ -14,12 +14,18 @@ Casbin uses the built-in `log` to print logs to the console by default, like: 2017/07/15 19:43:56 [Request: alice, data1, read ---> true] ``` -Logging is not enabled by default. +Logging is not enabled by default. You can toggle it via `Enforcer.EnableLog()` or the last parameter of `NewEnforcer()`. :::note -For Golang: We already support logging the model, enforce request, role, and policy in Golang. You can define your own log for logging Casbin.You can toggle it via `Enforcer.EnableLog()` or the last parameter of `NewEnforcer()`.  -For Python: 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. +For Golang: We already support logging the model, enforce request, role, and policy in Golang. You can define your own log for logging Casbin. + +::: + +:::note + +For Python: PyCasbin leverages the default Python logging mechanism. PyCasbin 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 logs 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. + ::: ### Use different loggers for different enforcers