From ca55f9917da8d657825bd2b46255be32421747a6 Mon Sep 17 00:00:00 2001 From: John Smith Date: Thu, 3 Sep 2020 20:01:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BF=9D=E5=AD=98=E5=88=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log/.gitkeep | 0 main.py | 14 +++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 log/.gitkeep diff --git a/log/.gitkeep b/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py index 6bb7dad..d6d2641 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import argparse import logging +import logging.handlers import os import webbrowser @@ -18,7 +19,9 @@ import update logger = logging.getLogger(__name__) -WEB_ROOT = os.path.join(os.path.dirname(__file__), 'frontend', 'dist') +BASE_PATH = os.path.dirname(os.path.realpath(__file__)) +WEB_ROOT = os.path.join(BASE_PATH, 'frontend', 'dist') +LOG_FILE_NAME = os.path.join(BASE_PATH, 'log', 'blivechat.log') routes = [ (r'/api/server_info', api.main.ServerInfoHandler), @@ -47,7 +50,7 @@ def main(): def parse_args(): - parser = argparse.ArgumentParser(description='用于OBS的仿YouTube风格的bilibili直播聊天层') + parser = argparse.ArgumentParser(description='用于OBS的仿YouTube风格的bilibili直播评论栏') parser.add_argument('--host', help='服务器host,默认为127.0.0.1', default='127.0.0.1') parser.add_argument('--port', help='服务器端口,默认为12450', type=int, default=12450) parser.add_argument('--debug', help='调试模式', action='store_true') @@ -55,11 +58,16 @@ def parse_args(): def init_logging(debug): + stream_handler = logging.StreamHandler() + file_handler = logging.handlers.TimedRotatingFileHandler( + LOG_FILE_NAME, encoding='utf-8', when='midnight', backupCount=7, delay=True + ) logging.basicConfig( format='{asctime} {levelname} [{name}]: {message}', datefmt='%Y-%m-%d %H:%M:%S', style='{', - level=logging.INFO if not debug else logging.DEBUG + level=logging.INFO if not debug else logging.DEBUG, + handlers=[stream_handler, file_handler] )