chore: 更新日志收集方法 (#203)

* fix: 修复无法构建docker镜像的问题

* Update Dockerfile

* chore: 更新日志收集方法

* chore: 遵守代码规范

* chore: update issue templates
This commit is contained in:
Night-stars-1 2023-11-24 16:06:21 +08:00 committed by GitHub
parent 137b9afb22
commit 2bf3fb71b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 25 deletions

View File

@ -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

View File

@ -1,6 +1,6 @@
name: 功能请求
description: Suggest an idea for this project
title: "[Feature] "
title: "[Feature] 请在这块简要说明需求否则该issue将会被关闭"
labels: [enhancement]
body:
- type: markdown

View File

@ -8,7 +8,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
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__":

View File

@ -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 @@ log.remove()
log.add(sys.stdout, level="INFO", colorize=True,
format="<cyan>{module}</cyan>.<cyan>{function}</cyan>"
":<cyan>{line}</cyan> - "
"<level>{message}</level>", filter=log_filter)
"<level>{message}</level>", filter=InterceptHandler)
log.add(path_log, level="DEBUG",
format="{time:HH:mm:ss} - "