5c028d7952
包含 FastAPI 后端、React 前端、队列/OCR/标签/待办等完整功能。 Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
778 B
Python
26 lines
778 B
Python
"""统一日志配置。"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import sys
|
|
|
|
|
|
def setup_logging(debug: bool = False) -> None:
|
|
"""初始化根 logger 的格式与级别。"""
|
|
level = logging.DEBUG if debug else logging.INFO
|
|
fmt = "%(asctime)s | %(levelname)-7s | %(name)s | %(message)s"
|
|
handler = logging.StreamHandler(sys.stdout)
|
|
handler.setFormatter(logging.Formatter(fmt))
|
|
root = logging.getLogger()
|
|
root.handlers.clear()
|
|
root.addHandler(handler)
|
|
root.setLevel(level)
|
|
# 降低第三方库噪音
|
|
for noisy in ("watchdog", "httpx", "PIL"):
|
|
logging.getLogger(noisy).setLevel(logging.WARNING)
|
|
|
|
|
|
def get_logger(name: str) -> logging.Logger:
|
|
"""统一入口获取 logger。"""
|
|
return logging.getLogger(name)
|