Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit a64ce58

Browse files
committed
fix: 更新日志格式,增强可读性并添加序列化支持
LOGGING_FORMAT = "<green>{time:YYYYMMDD HH:mm:ss}</green> | " # 颜色>时间 "{process.name} | " # 进程名 "{thread.name} | " # 进程名 "<cyan>{module}</cyan>.<cyan>{function}</cyan> | " # 模块名.方法名 ":<cyan>{line}</cyan> | " # 行号 "<level>{level}</level>: " # 等级 "<level>{message}</level>" # 日志内容
1 parent bcd9ce4 commit a64ce58

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/utils/loger/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
# 清空 root 日志器的 handlers
1717
logging.root.handlers = []
1818

19+
LOGGING_FORMAT = "<green>{time:YYYYMMDD HH:mm:ss}</green> | " # 颜色>时间
20+
"{process.name} | " # 进程名
21+
"{thread.name} | " # 进程名
22+
"<cyan>{module}</cyan>.<cyan>{function}</cyan> | " # 模块名.方法名
23+
":<cyan>{line}</cyan> | " # 行号
24+
"<level>{level}</level>: " # 等级
25+
"<level>{message}</level>" # 日志内容
26+
1927
# 定义一个拦截标准日志的处理器
2028
class InterceptHandler(logging.Handler):
2129
def emit(self, record):
@@ -36,10 +44,11 @@ def emit(self, record):
3644
logger.add(
3745
sys.stdout,
3846
level="DEBUG" if mcim_config.debug else "INFO",
39-
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{module}</cyan>.<cyan>{function}</cyan>.<cyan>{line}</cyan> | <cyan>{message}</cyan>",
47+
format=LOGGING_FORMAT,
4048
# colorize=True,
4149
# backtrace=True,
4250
# diagnose=True,
51+
serialize=True,
4352
)
4453

4554
# 拦截标准日志并重定向到 Loguru

0 commit comments

Comments
 (0)