Don't add more then one stderr handler
parent
b9a9b7a9a3
commit
d102b82566
26
piker/log.py
26
piker/log.py
|
@ -72,21 +72,21 @@ def get_console_log(level: str = None, name: str = None) -> logging.Logger:
|
||||||
if level:
|
if level:
|
||||||
log.setLevel(level.upper() if not isinstance(level, int) else level)
|
log.setLevel(level.upper() if not isinstance(level, int) else level)
|
||||||
|
|
||||||
if not any(
|
for handler in log.handlers:
|
||||||
handler.stream == sys.stderr for handler in log.handlers
|
if getattr(handler, 'stream', None) and handler.stream == sys.stderr:
|
||||||
if getattr(handler, 'stream', None)
|
break
|
||||||
):
|
else:
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
|
|
||||||
formatter = colorlog.ColoredFormatter(
|
formatter = colorlog.ColoredFormatter(
|
||||||
LOG_FORMAT,
|
LOG_FORMAT,
|
||||||
datefmt=DATE_FORMAT,
|
datefmt=DATE_FORMAT,
|
||||||
log_colors=STD_PALETTE,
|
log_colors=STD_PALETTE,
|
||||||
secondary_log_colors=BOLD_PALETTE,
|
secondary_log_colors=BOLD_PALETTE,
|
||||||
style='{',
|
style='{',
|
||||||
)
|
)
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
|
|
||||||
return log
|
return log
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue