report: add add_logging_handler & send_at_exit parameters
This commit is contained in:
parent
73795d27b8
commit
2736fc30ae
1 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue