From 5c8335876fba7a30f20d9437baa1d90ee90a283e Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Wed, 6 Feb 2013 21:04:54 +0000 Subject: [PATCH] minor bug fix to make --disable-coloring work on log messages too --- lib/core/common.py | 3 +++ lib/core/log.py | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 1ae589399..c4d93c5cd 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -729,6 +729,9 @@ def boldifyMessage(message): return retVal def setColor(message, bold=False): + if conf.disableColoring: + return message + retVal = message level = extractRegexResult(r"\[(?P[A-Z ]+)\]", message) or kb.get("stickyLevel") diff --git a/lib/core/log.py b/lib/core/log.py index efd0bd465..e860a30df 100644 --- a/lib/core/log.py +++ b/lib/core/log.py @@ -20,10 +20,20 @@ LOGGER_HANDLER = None try: from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler - LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout) - LOGGER_HANDLER.level_map[logging.getLevelName("PAYLOAD")] = (None, "cyan", False) - LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC OUT")] = (None, "magenta", False) - LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC IN")] = ("magenta", None, False) + disableColoring = False + + for argument in sys.argv: + if "disable-col" in argument: + disableColoring = True + break + + if disableColoring: + LOGGER_HANDLER = logging.StreamHandler(sys.stdout) + else: + LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout) + LOGGER_HANDLER.level_map[logging.getLevelName("PAYLOAD")] = (None, "cyan", False) + LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC OUT")] = (None, "magenta", False) + LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC IN")] = ("magenta", None, False) except ImportError: LOGGER_HANDLER = logging.StreamHandler(sys.stdout)