Skip to content

Commit

Permalink
chore: 更新日志收集方法 (#203)
Browse files Browse the repository at this point in the history
* fix: 修复无法构建docker镜像的问题

* Update Dockerfile

* chore: 更新日志收集方法

* chore: 遵守代码规范

* chore: update issue templates
  • Loading branch information
Night-stars-1 authored Nov 24, 2023
1 parent 137b9af commit 2bf3fb7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 问题反馈
description: Create a report to help us improve
title: "[Bug] "
title: "[Bug] 请在这块简要说明问题,否则该issue将会被关闭"
labels: ["bug"]
body:
- type: markdown
Expand Down Expand Up @@ -77,6 +77,7 @@ body:
label: MIUITask Log
description: |
在下方附上 MIUITask 输出日志 / MIUItask Log
不上传log该issue将会被关闭
validations:
required: true
- type: textarea
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 功能请求
description: Suggest an idea for this project
title: "[Feature] "
title: "[Feature] 请在这块简要说明需求,否则该issue将会被关闭"
labels: [enhancement]
body:
- type: markdown
Expand Down
5 changes: 3 additions & 2 deletions miuitask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__":
Expand Down
34 changes: 13 additions & 21 deletions utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
"""
'''
Date: 2023-11-12 14:05:06
LastEditors: Night-stars-1 [email protected]
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
Expand All @@ -37,7 +29,7 @@ def get_message():
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} - "
Expand Down

0 comments on commit 2bf3fb7

Please sign in to comment.