miui-auto-tasks/utils/logger.py
Night-stars-1 ea361a0e04
chore: captcha的参数拷贝,避免修改原参数 (#172)
* chore: captcha的参数拷贝,避免修改原参数
chore: 提升pylint分数,使代码更加规范

* fix: `@validator` cannot be applied to instance methods

* deleted:    .pylintrc

* chore: no-else-return

* chore: 优化代码,使其更符合PEP 8规范

* chore: 优化代码,使其更符合PEP 8规范

* chore: 优化代码,使其更符合PEP 8规范

* chore: 添加代码规范等级

* fix: fix dockerfile

* modified:   Dockerfile

* chore: 更新docker ci
2023-11-18 21:37:51 +11:00

47 lines
1.1 KiB
Python

'''
Date: 2023-11-12 14:05:06
LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2023-11-18 14:20:44
'''
import os
import sys
from loguru import logger
MESSAGE = ""
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
def get_message():
"""
说明:
返回消息
返回:
收集到的消息
"""
global MESSAGE # pylint: disable=global-variable-not-assigned
return MESSAGE
path_log = os.path.join("logs", '日志文件.log')
log = logger
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)
log.add(path_log, level="DEBUG",
format="{time:HH:mm:ss} - "
"{level}\t| "
"{module}.{function}:{line} - {message}",
rotation="1 days", enqueue=True, serialize=False, encoding="utf-8", retention="10 days")