Skip to content

Commit 651a352

Browse files
Copilothsluoyz
andcommitted
Refactor logging code to eliminate duplication
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
1 parent 5808193 commit 651a352

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

casbin/core_enforcer.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,17 +508,15 @@ def enforce_ex(self, *rvals):
508508
result = effect_to_bool(final_effect)
509509

510510
# Log request.
511-
if result:
512-
if self.logger.isEnabledFor(logging.INFO):
513-
req_str = "Request: "
514-
req_str = req_str + ", ".join([str(v) for v in rvals])
515-
req_str = req_str + " ---> %s" % result
511+
if (result and self.logger.isEnabledFor(logging.INFO)) or (
512+
not result and self.logger.isEnabledFor(logging.WARNING)
513+
):
514+
req_str = "Request: "
515+
req_str = req_str + ", ".join([str(v) for v in rvals])
516+
req_str = req_str + " ---> %s" % result
517+
if result:
516518
self.logger.info(req_str)
517-
else:
518-
if self.logger.isEnabledFor(logging.WARNING):
519-
req_str = "Request: "
520-
req_str = req_str + ", ".join([str(v) for v in rvals])
521-
req_str = req_str + " ---> %s" % result
519+
else:
522520
# leaving this in warning for now, if it's very noise this can be changed to info or debug,
523521
# or change the log level
524522
self.logger.warning(req_str)

0 commit comments

Comments
 (0)