diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 09ee876..b9cdb0f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,6 +1,6 @@ name: 问题反馈 description: Create a report to help us improve -title: "[Bug] " +title: "[Bug] 请在这块简要说明问题,否则该issue将会被关闭" labels: ["bug"] body: - type: markdown @@ -77,6 +77,7 @@ body: label: MIUITask Log description: | 在下方附上 MIUITask 输出日志 / MIUItask Log + 不上传log该issue将会被关闭 validations: required: true - type: textarea diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index f235740..2a2f410 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,6 +1,6 @@ name: 功能请求 description: Suggest an idea for this project -title: "[Feature] " +title: "[Feature] 请在这块简要说明需求,否则该issue将会被关闭" labels: [enhancement] body: - type: markdown diff --git a/miuitask.py b/miuitask.py index b1acfd7..2c5de77 100644 --- a/miuitask.py +++ b/miuitask.py @@ -8,7 +8,7 @@ from utils.api.login import Login from utils.api.sign import BaseSign from utils.config import ConfigManager -from utils.logger import get_message, log +from utils.logger import InterceptHandler, log from utils.request import notify_me from utils.system_info import print_info from utils.utils import get_token @@ -38,7 +38,8 @@ async def main(): log.error(f"未找到{task.name}任务") else: log.info(f"{task.name}任务已完成") - notify_me(get_message()) + log.info("`任务执行完毕`") + notify_me(InterceptHandler.message) if __name__ == "__main__": diff --git a/utils/logger.py b/utils/logger.py index ee2954b..3657994 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -1,34 +1,26 @@ -""" +''' Date: 2023-11-12 14:05:06 LastEditors: Night-stars-1 nujj1042633805@gmail.com -LastEditTime: 2023-11-18 14:20:44 -""" +LastEditTime: 2023-11-24 13:10:39 +''' import os import sys from loguru import logger -MESSAGE = "" +class InterceptHandler: + """拦截器""" -def log_filter(record: dict): - """loguru过滤器""" - global MESSAGE # pylint: disable=global-statement - if record["level"].no >= 20: - MESSAGE += f"{record.get('message')}\n" - return True + message = "" + """消息""" + def __init__(self, record: dict): + self.write(record) -def get_message(): - """ - 说明: - 返回消息 - 返回: - 收集到的消息 - """ - global MESSAGE # pylint: disable=global-variable-not-assigned - return MESSAGE - + def write(self, record: dict): + """写入""" + InterceptHandler.message += record.get('message') path_log = os.path.join("logs", '日志文件.log') log = logger @@ -37,7 +29,7 @@ def get_message(): log.add(sys.stdout, level="INFO", colorize=True, format="{module}.{function}" ":{line} - " - "{message}", filter=log_filter) + "{message}", filter=InterceptHandler) log.add(path_log, level="DEBUG", format="{time:HH:mm:ss} - "