Files
mcp-server/common/logging.py
T
2026-06-24 15:09:59 +08:00

51 lines
1.3 KiB
Python

# coding=utf-8
"""
@Time :2026/6/24
@Author :tao.chen
Process-wide loguru configuration. Import `logger` from here in every
module instead of instantiating new loggers.
Levels used in this project:
DEBUG - entry/exit of public tools, subprocess commands, file I/O paths
INFO - business events (job submitted, status changed, connection saved)
WARNING - recoverable problems (transient YARN issues, retry-able)
ERROR - raised exceptions (caller will see the traceback)
"""
import sys
from pathlib import Path
from loguru import logger
Path("data/logs/debug").mkdir(parents=True, exist_ok=True)
Path("data/logs/info").mkdir(parents=True, exist_ok=True)
logger.remove()
logger.add(
sys.stderr,
level="DEBUG",
format=(
"<green>{time:HH:mm:ss.SSS}</green> | "
"<level>{level: <7}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level>"
),
enqueue=True,
colorize=True,
)
logger.add(
"data/logs/debug/{time:YYYY-MM-DD}.log",
level="DEBUG",
enqueue=True,
retention="30 days",
compression="gz",
colorize=True,
)
logger.add(
"data/logs/info/{time:YYYY-MM-DD}.log",
level="INFO",
enqueue=True,
retention="30 days",
compression="gz",
encoding="utf-8",
)