From a2938c01884253315b8d63212817637a6677a22a Mon Sep 17 00:00:00 2001 From: NogaNHS <127490765+NogaNHS@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:28:47 +0000 Subject: [PATCH] Audit logger bug fix (#166) change audit logger to a class var to prevent initiating logger multiple times --- lambdas/utils/audit_logging_setup.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lambdas/utils/audit_logging_setup.py b/lambdas/utils/audit_logging_setup.py index 5324b343a..4b887d586 100644 --- a/lambdas/utils/audit_logging_setup.py +++ b/lambdas/utils/audit_logging_setup.py @@ -5,18 +5,23 @@ class LoggingService: + + audit_logger = None + def __init__(self, name): self.name = name self.logger = logging.getLogger(name) self.logger.setLevel(logging.INFO) - - self.audit_logger = logging.getLogger("audit") - self.audit_handler = SensitiveAuditService() + self.configure_audit_logger() self.formatter = LoggingFormatter() logging.Formatter.format = self.formatter.format - self.audit_logger.addHandler(self.audit_handler) - self.audit_logger.setLevel(logging.INFO) + def configure_audit_logger(self): + if self.__class__.audit_logger is None: + self.__class__.audit_logger = logging.getLogger("audit") + audit_handler = SensitiveAuditService() + self.__class__.audit_logger.addHandler(audit_handler) + self.__class__.audit_logger.setLevel(logging.INFO) def audit_splunk_info(self, msg, args: dict = None): logging.getLogger("audit.{}".format(self.name))