report: add add_logging_handler & send_at_exit parameters

This commit is contained in:
Benjamin Renard 2023-12-14 21:41:16 +01:00
parent 73795d27b8
commit 2736fc30ae
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -27,9 +27,18 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance
formatter = None formatter = None
email_client = 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) super().__init__(**kwargs)
self.email_client = email_client self.email_client = email_client
self.add_logging_handler = add_logging_handler
self._send_at_exit = send_at_exit
self._attachment_files = [] self._attachment_files = []
self._attachment_payloads = [] self._attachment_payloads = []
@ -81,6 +90,11 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance
self.formatter = logging.Formatter(self._get_option("logformat")) self.formatter = logging.Formatter(self._get_option("logformat"))
self.handler.setFormatter(self.formatter) 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): def get_handler(self):
"""Retreive logging handler""" """Retreive logging handler"""
return self.handler return self.handler