From aa8238d5e0f51c86b27e1d85ced77007d37434e3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 9 Nov 2018 01:35:51 -0500 Subject: [PATCH] Revert allowing multiple stream handlers; clutters test output --- tractor/log.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tractor/log.py b/tractor/log.py index 5a65603..f8c8d1b 100644 --- a/tractor/log.py +++ b/tractor/log.py @@ -1,6 +1,7 @@ """ Log like a forester! """ +import sys from functools import partial import logging import colorlog # type: ignore @@ -73,16 +74,21 @@ def get_console_log(level: str = None, name: str = None) -> logging.Logger: return log log.setLevel(level.upper() if not isinstance(level, int) else level) - handler = logging.StreamHandler() - formatter = colorlog.ColoredFormatter( - LOG_FORMAT, - datefmt=DATE_FORMAT, - log_colors=STD_PALETTE, - secondary_log_colors=BOLD_PALETTE, - style='{', - ) - handler.setFormatter(formatter) - log.addHandler(handler) + + if not any( + handler.stream == sys.stderr for handler in log.handlers + if getattr(handler, 'stream', None) + ): + handler = logging.StreamHandler() + formatter = colorlog.ColoredFormatter( + LOG_FORMAT, + datefmt=DATE_FORMAT, + log_colors=STD_PALETTE, + secondary_log_colors=BOLD_PALETTE, + style='{', + ) + handler.setFormatter(formatter) + log.addHandler(handler) return log