Skip to content

Commit

Permalink
日志保存到文件
Browse files Browse the repository at this point in the history
  • Loading branch information
xfgryujk committed Sep 3, 2020
1 parent 4d58245 commit ca55f99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Empty file added log/.gitkeep
Empty file.
14 changes: 11 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import logging
import logging.handlers
import os
import webbrowser

Expand All @@ -18,7 +19,9 @@

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),
Expand Down Expand Up @@ -47,19 +50,24 @@ 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')
return parser.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]
)


Expand Down

0 comments on commit ca55f99

Please sign in to comment.