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:
Alexey Stepanov 2016-09-07 09:38:04 +03:00 committed by Alexey Stepanov
parent c95b137224
commit 3315d741f2
1 changed files with 5 additions and 1 deletions

View File

@ -49,9 +49,13 @@ def set_console_formatter(**formatter_kwargs):
for handler in root_logger.handlers:
if handler.__class__ is logging.StreamHandler: # Skip subclasses
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
else:
return # Didn't find any StreamHandlers there
return # Didn't find any suitable StreamHandlers there
formatter = ColorFormatter(**formatter_kwargs)
console_handler.setFormatter(formatter)