From 31ceb0cb6ccd828b0a884fd2da85e680128946c4 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 7 Aug 2012 10:57:29 +0200 Subject: [PATCH] Fix for an Issue #140 --- lib/core/common.py | 2 +- thirdparty/ansistrm/ansistrm.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index f198ce58f..ec76a73fc 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -701,7 +701,7 @@ def setColor(message, bold=False): retVal = message level = extractRegexResult(r"\[(?P[A-Z ]+)\]", message) or kb.get("stickyLevel") - if message and hasattr(LOGGER_HANDLER, "level_map"): # colorizing handler + if message and getattr(LOGGER_HANDLER, "is_tty", False): # colorizing handler if bold: retVal = colored(message, color=None, on_color=None, attrs=("bold",)) elif level: diff --git a/thirdparty/ansistrm/ansistrm.py b/thirdparty/ansistrm/ansistrm.py index 6f391a349..8c275e23a 100644 --- a/thirdparty/ansistrm/ansistrm.py +++ b/thirdparty/ansistrm/ansistrm.py @@ -51,6 +51,8 @@ class ColorizingStreamHandler(logging.StreamHandler): stream = self.stream if not self.is_tty: + if message and message[0] == "\r": + message = message[1:] stream.write(message) else: self.output_colorized(message) @@ -122,7 +124,7 @@ class ColorizingStreamHandler(logging.StreamHandler): ctypes.windll.kernel32.SetConsoleTextAttribute(h, color) def colorize(self, message, record): - if record.levelno in self.level_map: + if record.levelno in self.level_map and self.is_tty: bg, fg, bold = self.level_map[record.levelno] params = []