From: Vagisha Gupta Date: Mon, 5 Aug 2019 09:10:51 +0000 (+0530) Subject: Add a check to apply colour if output stream on tty X-Git-Tag: 1.1.0rc1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ee0abd50ec1263b3d9f6131dd37688114bb6d99;p=thirdparty%2Fsuricata-update.git Add a check to apply colour if output stream on tty --- diff --git a/suricata/update/loghandler.py b/suricata/update/loghandler.py index ed63569..dc10504 100644 --- a/suricata/update/loghandler.py +++ b/suricata/update/loghandler.py @@ -16,6 +16,7 @@ # 02110-1301, USA. import sys +import os import logging import time @@ -65,16 +66,22 @@ class SuriColourLogHandler(logging.StreamHandler): level_prefix = self.YELLOW message_prefix = "" - self.stream.write("%s%s%s - <%s%s%s> -- %s%s%s\n" % ( - self.GREEN, - self.formatTime(record), - self.RESET, - level_prefix, - record.levelname.title(), - self.RESET, - message_prefix, - self.mask_secrets(record.getMessage()), - self.RESET)) + if os.isatty(self.stream.fileno()): + self.stream.write("%s%s%s - <%s%s%s> -- %s%s%s\n" % ( + self.GREEN, + self.formatTime(record), + self.RESET, + level_prefix, + record.levelname.title(), + self.RESET, + message_prefix, + self.mask_secrets(record.getMessage()), + self.RESET)) + else: + self.stream.write("%s - <%s> -- %s\n" % ( + self.formatTime(record), + record.levelname.title(), + self.mask_secrets(record.getMessage()))) def mask_secrets(self, msg): for secret in secrets: diff --git a/suricata/update/main.py b/suricata/update/main.py index ebce0b6..60881ee 100644 --- a/suricata/update/main.py +++ b/suricata/update/main.py @@ -71,7 +71,7 @@ except: revision = None # Initialize logging, use colour if on a tty. -if len(logging.root.handlers) == 0 and os.isatty(sys.stderr.fileno()): +if len(logging.root.handlers) == 0: logger = logging.getLogger() suricata.update.loghandler.configure_logging() logger.setLevel(level=logging.INFO)