From 2736fc30ae6912643c194ee8413798e2cd6b01ab Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 14 Dec 2023 21:41:16 +0100 Subject: [PATCH] report: add add_logging_handler & send_at_exit parameters --- mylib/report.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mylib/report.py b/mylib/report.py index 5026283..69f8852 100644 --- a/mylib/report.py +++ b/mylib/report.py @@ -27,9 +27,18 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance formatter = None email_client = None - def __init__(self, email_client=None, initialize=True, **kwargs): + def __init__( + self, + email_client=None, + add_logging_handler=False, + send_at_exit=None, + initialize=True, + **kwargs, + ): super().__init__(**kwargs) self.email_client = email_client + self.add_logging_handler = add_logging_handler + self._send_at_exit = send_at_exit self._attachment_files = [] self._attachment_payloads = [] @@ -81,6 +90,11 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance self.formatter = logging.Formatter(self._get_option("logformat")) self.handler.setFormatter(self.formatter) + if self.add_logging_handler: + logging.getLogger().addHandler(self.handler) + if self._send_at_exit: + self.send_at_exit() + def get_handler(self): """Retreive logging handler""" return self.handler