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:
parent
3b693c2b91
commit
ddac0d5782
@ -44,9 +44,11 @@ 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,18 +92,23 @@ def enable_logging(
|
|||||||
|
|
||||||
formatter = logging.Formatter(format_template)
|
formatter = logging.Formatter(format_template)
|
||||||
|
|
||||||
handlers = []
|
if handlers:
|
||||||
|
for handler in handlers:
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
|
||||||
if stream is not None:
|
else:
|
||||||
console = logging.StreamHandler(stream)
|
handlers = []
|
||||||
if format_stream:
|
|
||||||
console.setFormatter(formatter)
|
|
||||||
handlers.append(console)
|
|
||||||
|
|
||||||
if path is not None:
|
if stream is not None:
|
||||||
file_handler = logging.FileHandler(path)
|
console = logging.StreamHandler(stream)
|
||||||
file_handler.setFormatter(formatter)
|
if format_stream:
|
||||||
handlers.append(file_handler)
|
console.setFormatter(formatter)
|
||||||
|
handlers.append(console)
|
||||||
|
|
||||||
|
if path is not None:
|
||||||
|
file_handler = logging.FileHandler(path)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
|
handlers.append(file_handler)
|
||||||
|
|
||||||
setup_logging('openstack', handlers=handlers, level=level)
|
setup_logging('openstack', handlers=handlers, level=level)
|
||||||
setup_logging('keystoneauth', handlers=handlers, level=level)
|
setup_logging('keystoneauth', handlers=handlers, level=level)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user