Colorize output on tty only
Check ConsoleHandler stream for tty and colorize only if True. On CI colorized output is not processed and metacharacters simply reproduced in output as-is. Change-Id: I802e3d338c318d6fbb61dd556e13a2fad7eda121
This commit is contained in:
parent
c95b137224
commit
3315d741f2
|
@ -49,9 +49,13 @@ def set_console_formatter(**formatter_kwargs):
|
||||||
for handler in root_logger.handlers:
|
for handler in root_logger.handlers:
|
||||||
if handler.__class__ is logging.StreamHandler: # Skip subclasses
|
if handler.__class__ is logging.StreamHandler: # Skip subclasses
|
||||||
console_handler = handler
|
console_handler = handler
|
||||||
|
# Skip if not a tty (default ssh, redirect, ...)
|
||||||
|
isatty = getattr(handler.stream, 'isatty', None)
|
||||||
|
if isatty is None or not isatty():
|
||||||
|
continue
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return # Didn't find any StreamHandlers there
|
return # Didn't find any suitable StreamHandlers there
|
||||||
formatter = ColorFormatter(**formatter_kwargs)
|
formatter = ColorFormatter(**formatter_kwargs)
|
||||||
console_handler.setFormatter(formatter)
|
console_handler.setFormatter(formatter)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue