From 602f70ff10aff846fbb9eb65e60ae3e1335c02e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sun, 14 Feb 2021 19:58:39 +0800 Subject: [PATCH] =?UTF-8?q?DEMO=20making=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/main.py | 8 ++++---- configs/logging.json5 | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/main.py b/bin/main.py index 8c30b14..e8fa687 100644 --- a/bin/main.py +++ b/bin/main.py @@ -44,7 +44,7 @@ class Game: self.client_log_config = self.log_config['client'] self.client_logger = logging.getLogger('client') self.client_fmt = logging.Formatter( - fmt="[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s", + fmt=self.client_log_config['fmt'], datefmt=self.client_log_config['date_fmt']) self.client_stream_handler = logging.StreamHandler() self.client_stream_handler.setLevel(self.client_log_config['level']) @@ -54,7 +54,7 @@ class Game: self.server_log_config = self.log_config['server'] self.server_logger = logging.getLogger('server') self.server_fmt = logging.Formatter( - fmt="[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s", + fmt=self.server_log_config['fmt'], datefmt=self.server_log_config['date_fmt']) self.server_stream_handler = logging.StreamHandler() self.server_stream_handler.setLevel(self.server_log_config['level']) @@ -62,8 +62,8 @@ class Game: self.server_logger.addHandler(self.server_stream_handler) # file logger self.log_formatter = logging.Formatter( - fmt="[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s", - datefmt=self.log_config['date_fmt']) + fmt=self.log_file_config['fmt'], + datefmt=self.log_file_config['date_fmt']) # client and server self.client = client.RenderThread( self.client_logger, self.dicts, self.lists, net_mode='local') diff --git a/configs/logging.json5 b/configs/logging.json5 index 7d3881c..c6f38ac 100644 --- a/configs/logging.json5 +++ b/configs/logging.json5 @@ -2,20 +2,24 @@ 'server': { 'level': 'DEBUG', // option: CRITICAL ERROR WARNING INFO DEBUG - 'fmt': '', - // format + 'fmt': '[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s', + // format of log 'date_fmt': '%Y-%m-%d %H-%M-%S', // format at https://docs.python.org/zh-cn/3.8/library/time.html#time.strftime }, 'client': { 'level': 'DEBUG', // option: CRITICAL ERROR WARNING INFO DEBUG + 'fmt': '[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s', + // format of log 'date_fmt': '%Y-%m-%d %H-%M-%S', // format at https://docs.python.org/zh-cn/3.8/library/time.html#time.strftime }, 'file': { 'level': 'DEBUG', // option: CRITICAL ERROR WARNING INFO DEBUG + 'fmt': '[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s', + // format of log 'date_fmt': '%Y-%m-%d %H-%M-%S', // format at https://docs.python.org/zh-cn/3.8/library/time.html#time.strftime 'filename': {