mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-25 12:21:00 +08:00
日志保存到文件
This commit is contained in:
parent
4d58245ad9
commit
ca55f9917d
0
log/.gitkeep
Normal file
0
log/.gitkeep
Normal file
14
main.py
14
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]
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user