2023-11-22 04:02:10 +00:00
|
|
|
"""
|
2023-11-18 10:37:51 +00:00
|
|
|
Date: 2023-11-12 14:05:06
|
2023-11-13 13:18:59 +00:00
|
|
|
LastEditors: Night-stars-1 nujj1042633805@gmail.com
|
2023-11-18 10:37:51 +00:00
|
|
|
LastEditTime: 2023-11-18 14:20:44
|
2023-11-22 04:02:10 +00:00
|
|
|
"""
|
2023-11-13 13:18:59 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from loguru import logger
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
MESSAGE = ""
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
def log_filter(record: dict):
|
|
|
|
"""loguru过滤器"""
|
2023-11-22 04:02:10 +00:00
|
|
|
global MESSAGE # pylint: disable=global-statement
|
2023-11-13 13:18:59 +00:00
|
|
|
if record["level"].no >= 20:
|
2023-11-18 10:37:51 +00:00
|
|
|
MESSAGE += f"{record.get('message')}\n"
|
2023-11-13 13:18:59 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def get_message():
|
|
|
|
"""
|
|
|
|
说明:
|
|
|
|
返回消息
|
|
|
|
返回:
|
|
|
|
收集到的消息
|
|
|
|
"""
|
2023-11-22 04:02:10 +00:00
|
|
|
global MESSAGE # pylint: disable=global-variable-not-assigned
|
2023-11-18 10:37:51 +00:00
|
|
|
return MESSAGE
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
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> - "
|
2023-11-18 10:37:51 +00:00
|
|
|
"<level>{message}</level>", filter=log_filter)
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
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")
|