1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Do not color logger message

This commit is contained in:
Julien Duponchelle 2015-01-20 15:18:57 +01:00
parent 4488cc3960
commit 0b97509a74

View File

@ -34,7 +34,7 @@ class ColouredFormatter(logging.Formatter):
message = super().format(record) message = super().format(record)
if not colour: if not colour:
return message return message.replace("#RESET#", "")
level_no = record.levelno level_no = record.levelno
if level_no >= logging.CRITICAL: if level_no >= logging.CRITICAL:
@ -50,6 +50,7 @@ class ColouredFormatter(logging.Formatter):
else: else:
colour = self.RESET colour = self.RESET
message = message.replace("#RESET#", self.RESET)
message = '{colour}{message}{reset}'.format(colour=colour, message=message, reset=self.RESET) message = '{colour}{message}{reset}'.format(colour=colour, message=message, reset=self.RESET)
return message return message
@ -76,7 +77,7 @@ class ColouredStreamHandler(logging.StreamHandler):
def init_logger(level,quiet=False): def init_logger(level,quiet=False):
stream_handler = ColouredStreamHandler(sys.stdout) stream_handler = ColouredStreamHandler(sys.stdout)
stream_handler.formatter = ColouredFormatter("{asctime} {levelname:8} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{") stream_handler.formatter = ColouredFormatter("{asctime} {levelname:8} {filename}:{lineno}#RESET# {message}", "%Y-%m-%d %H:%M:%S", "{")
if quiet: if quiet:
stream_handler.addFilter(logging.Filter(name="user_facing")) stream_handler.addFilter(logging.Filter(name="user_facing"))
logging.getLogger('user_facing').propagate = False logging.getLogger('user_facing').propagate = False