miui-auto-tasks/utils/logger.py
Night-stars-1 762273a66b
chore: 删除测试代码 (#207)
* fix: 修复无法构建docker镜像的问题

* Update Dockerfile

* chore: 更新日志收集方法

* chore: 遵守代码规范

* chore: update issue templates

* chore: 删除测试代码

* chore: 更改日志输出样式

* chore: docker生成配置时随机生成自动运行时间

* chore: trailing-whitespace

* chore: 日志添加换行
2023-11-25 12:08:51 +11:00

41 lines
1.1 KiB
Python

'''
Date: 2023-11-12 14:05:06
LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2023-11-24 17:39:16
'''
import os
import sys
from loguru import logger
class InterceptHandler:
"""拦截器"""
message = ""
"""消息"""
def __init__(self, record: dict):
self.write(record)
def write(self, record: dict):
"""写入"""
InterceptHandler.message += f"{record.get('message')}\n"
path_log = os.path.join("logs", '日志文件.log')
log = logger
log.remove()
log.add(sys.stdout, level="INFO", colorize=True,
format="<green>{time:HH:mm:ss}</green> - "
"<level>{level: <5}</level> | "
"<cyan>{module}</cyan>.<cyan>{function}</cyan>"
":<cyan>{line}</cyan> - "
"<level>{message}</level>", filter=InterceptHandler)
log.add(path_log, level="DEBUG",
format="{time:HH:mm:ss} - "
"{level: <5} | "
"{module}.{function}:{line} - {message}",
rotation="1 days", enqueue=True, serialize=False, encoding="utf-8", retention="10 days")