Revert allowing multiple stream handlers; clutters test output

loglevel_to_tractor_tests
Tyler Goodlet 2018-11-09 01:35:51 -05:00
parent 8b7bf4fc07
commit aa8238d5e0
1 changed files with 16 additions and 10 deletions

View File

@ -1,6 +1,7 @@
""" """
Log like a forester! Log like a forester!
""" """
import sys
from functools import partial from functools import partial
import logging import logging
import colorlog # type: ignore import colorlog # type: ignore
@ -73,16 +74,21 @@ def get_console_log(level: str = None, name: str = None) -> logging.Logger:
return log return log
log.setLevel(level.upper() if not isinstance(level, int) else level) log.setLevel(level.upper() if not isinstance(level, int) else level)
handler = logging.StreamHandler()
formatter = colorlog.ColoredFormatter( if not any(
LOG_FORMAT, handler.stream == sys.stderr for handler in log.handlers
datefmt=DATE_FORMAT, if getattr(handler, 'stream', None)
log_colors=STD_PALETTE, ):
secondary_log_colors=BOLD_PALETTE, handler = logging.StreamHandler()
style='{', formatter = colorlog.ColoredFormatter(
) LOG_FORMAT,
handler.setFormatter(formatter) datefmt=DATE_FORMAT,
log.addHandler(handler) log_colors=STD_PALETTE,
secondary_log_colors=BOLD_PALETTE,
style='{',
)
handler.setFormatter(formatter)
log.addHandler(handler)
return log return log