2023-11-24 08:06:21 +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-25 01:08:51 +00:00
|
|
|
LastEditTime: 2023-11-24 17:39:16
|
2023-11-24 08:06:21 +00:00
|
|
|
'''
|
2023-11-13 13:18:59 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from loguru import logger
|
|
|
|
|
|
|
|
|
2023-11-24 08:06:21 +00:00
|
|
|
class InterceptHandler:
|
|
|
|
"""拦截器"""
|
2023-11-13 13:18:59 +00:00
|
|
|
|
2023-11-24 08:06:21 +00:00
|
|
|
message = ""
|
|
|
|
"""消息"""
|
2023-11-13 13:18:59 +00:00
|
|
|
|
2023-11-24 08:06:21 +00:00
|
|
|
def __init__(self, record: dict):
|
|
|
|
self.write(record)
|
2023-11-13 13:18:59 +00:00
|
|
|
|
2023-11-24 08:06:21 +00:00
|
|
|
def write(self, record: dict):
|
|
|
|
"""写入"""
|
2023-11-25 01:08:51 +00:00
|
|
|
InterceptHandler.message += f"{record.get('message')}\n"
|
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,
|
2023-11-25 01:08:51 +00:00
|
|
|
format="<green>{time:HH:mm:ss}</green> - "
|
|
|
|
"<level>{level: <5}</level> | "
|
|
|
|
"<cyan>{module}</cyan>.<cyan>{function}</cyan>"
|
2023-11-13 13:18:59 +00:00
|
|
|
":<cyan>{line}</cyan> - "
|
2023-11-24 08:06:21 +00:00
|
|
|
"<level>{message}</level>", filter=InterceptHandler)
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
log.add(path_log, level="DEBUG",
|
|
|
|
format="{time:HH:mm:ss} - "
|
2023-11-25 01:08:51 +00:00
|
|
|
"{level: <5} | "
|
2023-11-13 13:18:59 +00:00
|
|
|
"{module}.{function}:{line} - {message}",
|
|
|
|
rotation="1 days", enqueue=True, serialize=False, encoding="utf-8", retention="10 days")
|