From cee99a63771d330ffa85e8d8e1ceaf80d16036b3 Mon Sep 17 00:00:00 2001 From: hanhxiao Date: Fri, 30 Aug 2019 12:26:15 +0800 Subject: [PATCH] fix(logger): change the color semantic for loglevel --- gnes/helper.py | 5 ++--- gnes/service/base.py | 10 +++++----- gnes/service/frontend.py | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/gnes/helper.py b/gnes/helper.py index e42964d8..e157dbcd 100644 --- a/gnes/helper.py +++ b/gnes/helper.py @@ -191,10 +191,9 @@ class ColoredFormatter(Formatter): MAPPING = { 'DEBUG': dict(color='white', on_color=None), # white 'INFO': dict(color='white', on_color=None), # cyan - 'WARNING': dict(color='red', on_color='on_yellow'), # yellow + 'WARNING': dict(color='yellow', on_color='on_grey'), # yellow 'ERROR': dict(color='white', on_color='on_red'), # 31 for red - 'CRITICAL': dict(color='red', on_color='on_white'), # white on red bg - 'SUCCESS': dict(color='white', on_color='on_green'), # green + 'CRITICAL': dict(color='white', on_color='on_green'), # white on red bg } PREFIX = '\033[' diff --git a/gnes/service/base.py b/gnes/service/base.py index 2d06ce2b..b649d482 100644 --- a/gnes/service/base.py +++ b/gnes/service/base.py @@ -255,7 +255,7 @@ def dump(self): self._model.dump() self.logger.info('dumping finished!') else: - self.logger.info('pass dumping as "read_only" set to true.') + self.logger.info('no dumping as "read_only" set to true.') def message_handler(self, msg: 'gnes_pb2.Message', out_sck, ctrl_sck): try: @@ -286,8 +286,8 @@ def message_handler(self, msg: 'gnes_pb2.Message', out_sck, ctrl_sck): except EventLoopEnd: send_message(out_sock, msg, timeout=self.args.timeout) raise EventLoopEnd - except ServiceError as e: - self.logger.error(e) + except ServiceError as ex: + self.logger.error(ex, exc_info=True) @zmqd.context() def _run(self, ctx): @@ -314,7 +314,7 @@ def _run(self, ctx): self.is_ready.set() self.is_event_loop.set() self._start_auto_dump() - self.logger.info(colored('ready and listening', color='white', on_color='on_green')) + self.logger.critical('ready and listening') while self.is_event_loop.is_set(): pull_sock = None socks = dict(poller.poll()) @@ -347,7 +347,7 @@ def _run(self, ctx): in_sock.close() out_sock.close() ctrl_sock.close() - self.logger.info('terminated') + self.logger.critical('terminated') def post_init(self): pass diff --git a/gnes/service/frontend.py b/gnes/service/frontend.py index e5ded6e7..b2488e33 100644 --- a/gnes/service/frontend.py +++ b/gnes/service/frontend.py @@ -40,7 +40,7 @@ def __init__(self, args): def __enter__(self): self.server.start() - self.logger.info('listening at: %s' % self.bind_address) + self.logger.critical('listening at: %s' % self.bind_address) return self def __exit__(self, exc_type, exc_val, exc_tb):