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
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