Allow passing in a logging handler

We create formatters on the fly in enable_logging. Allow passing
in a custom handler that we wire up.

Change-Id: Ic01540fe80be8c91e0121a33a2bfa9c9dc4b2da2
This commit is contained in:
Monty Taylor 2020-07-09 08:35:13 -05:00
parent 3b693c2b91
commit ddac0d5782

View File

@ -46,7 +46,9 @@ def setup_logging(name, handlers=None, level=None):
def enable_logging( def enable_logging(
debug=False, http_debug=False, path=None, stream=None, debug=False, http_debug=False, path=None, stream=None,
format_stream=False, format_stream=False,
format_template='%(asctime)s %(levelname)s: %(name)s %(message)s'): format_template='%(asctime)s %(levelname)s: %(name)s %(message)s',
handlers=None,
):
"""Enable logging output. """Enable logging output.
Helper function to enable logging. This function is available for Helper function to enable logging. This function is available for
@ -90,6 +92,11 @@ def enable_logging(
formatter = logging.Formatter(format_template) formatter = logging.Formatter(format_template)
if handlers:
for handler in handlers:
handler.setFormatter(formatter)
else:
handlers = [] handlers = []
if stream is not None: if stream is not None: