Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c83358

Browse files
committed
minor bug fix to make --disable-coloring work on log messages too
1 parent 2fa2f30 commit 5c83358

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

lib/core/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ def boldifyMessage(message):
729729
return retVal
730730

731731
def setColor(message, bold=False):
732+
if conf.disableColoring:
733+
return message
734+
732735
retVal = message
733736
level = extractRegexResult(r"\[(?P<result>[A-Z ]+)\]", message) or kb.get("stickyLevel")
734737

lib/core/log.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
try:
2121
from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler
2222

23-
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
24-
LOGGER_HANDLER.level_map[logging.getLevelName("PAYLOAD")] = (None, "cyan", False)
25-
LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC OUT")] = (None, "magenta", False)
26-
LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC IN")] = ("magenta", None, False)
23+
disableColoring = False
24+
25+
for argument in sys.argv:
26+
if "disable-col" in argument:
27+
disableColoring = True
28+
break
29+
30+
if disableColoring:
31+
LOGGER_HANDLER = logging.StreamHandler(sys.stdout)
32+
else:
33+
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
34+
LOGGER_HANDLER.level_map[logging.getLevelName("PAYLOAD")] = (None, "cyan", False)
35+
LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC OUT")] = (None, "magenta", False)
36+
LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC IN")] = ("magenta", None, False)
2737
except ImportError:
2838
LOGGER_HANDLER = logging.StreamHandler(sys.stdout)
2939

0 commit comments

Comments
 (0)