Skip to content

Commit 2bf3fb7

Browse files
chore: 更新日志收集方法 (#203)
* fix: 修复无法构建docker镜像的问题 * Update Dockerfile * chore: 更新日志收集方法 * chore: 遵守代码规范 * chore: update issue templates
1 parent 137b9af commit 2bf3fb7

4 files changed

Lines changed: 19 additions & 25 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 问题反馈
22
description: Create a report to help us improve
3-
title: "[Bug] "
3+
title: "[Bug] 请在这块简要说明问题,否则该issue将会被关闭"
44
labels: ["bug"]
55
body:
66
- type: markdown
@@ -77,6 +77,7 @@ body:
7777
label: MIUITask Log
7878
description: |
7979
在下方附上 MIUITask 输出日志 / MIUItask Log
80+
不上传log该issue将会被关闭
8081
validations:
8182
required: true
8283
- type: textarea

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 功能请求
22
description: Suggest an idea for this project
3-
title: "[Feature] "
3+
title: "[Feature] 请在这块简要说明需求,否则该issue将会被关闭"
44
labels: [enhancement]
55
body:
66
- type: markdown

miuitask.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from utils.api.login import Login
99
from utils.api.sign import BaseSign
1010
from utils.config import ConfigManager
11-
from utils.logger import get_message, log
11+
from utils.logger import InterceptHandler, log
1212
from utils.request import notify_me
1313
from utils.system_info import print_info
1414
from utils.utils import get_token
@@ -38,7 +38,8 @@ async def main():
3838
log.error(f"未找到{task.name}任务")
3939
else:
4040
log.info(f"{task.name}任务已完成")
41-
notify_me(get_message())
41+
log.info("`任务执行完毕`")
42+
notify_me(InterceptHandler.message)
4243

4344

4445
if __name__ == "__main__":

utils/logger.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
"""
1+
'''
22
Date: 2023-11-12 14:05:06
33
LastEditors: Night-stars-1 nujj1042633805@gmail.com
4-
LastEditTime: 2023-11-18 14:20:44
5-
"""
4+
LastEditTime: 2023-11-24 13:10:39
5+
'''
66
import os
77
import sys
88

99
from loguru import logger
1010

11-
MESSAGE = ""
1211

12+
class InterceptHandler:
13+
"""拦截器"""
1314

14-
def log_filter(record: dict):
15-
"""loguru过滤器"""
16-
global MESSAGE # pylint: disable=global-statement
17-
if record["level"].no >= 20:
18-
MESSAGE += f"{record.get('message')}\n"
19-
return True
15+
message = ""
16+
"""消息"""
2017

18+
def __init__(self, record: dict):
19+
self.write(record)
2120

22-
def get_message():
23-
"""
24-
说明:
25-
返回消息
26-
返回:
27-
收集到的消息
28-
"""
29-
global MESSAGE # pylint: disable=global-variable-not-assigned
30-
return MESSAGE
31-
21+
def write(self, record: dict):
22+
"""写入"""
23+
InterceptHandler.message += record.get('message')
3224

3325
path_log = os.path.join("logs", '日志文件.log')
3426
log = logger
@@ -37,7 +29,7 @@ def get_message():
3729
log.add(sys.stdout, level="INFO", colorize=True,
3830
format="<cyan>{module}</cyan>.<cyan>{function}</cyan>"
3931
":<cyan>{line}</cyan> - "
40-
"<level>{message}</level>", filter=log_filter)
32+
"<level>{message}</level>", filter=InterceptHandler)
4133

4234
log.add(path_log, level="DEBUG",
4335
format="{time:HH:mm:ss} - "

0 commit comments

Comments
 (0)