feat: logging to file

This commit is contained in:
Claude
2026-06-24 15:09:59 +08:00
parent 5c7dcf57cc
commit b3eabe1fb6
+23 -1
View File
@@ -13,8 +13,10 @@ Levels used in this project:
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(
@@ -26,4 +28,24 @@ logger.add(
"<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",
)