第一步

This commit is contained in:
amb
2026-09-01 11:53:59 +08:00
commit 47bf6cc5ca
66 changed files with 6501 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
"""结构化日志配置。"""
import logging
import sys
_CONFIGURED = False
def setup_logging(level: int = logging.INFO) -> None:
global _CONFIGURED
if _CONFIGURED:
return
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(
logging.Formatter(
fmt="%(asctime)s | %(levelname)-7s | %(name)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
)
root = logging.getLogger()
root.setLevel(level)
root.handlers = [handler]
for noisy in ("uvicorn.access", "asyncio"):
logging.getLogger(noisy).setLevel(logging.WARNING)
_CONFIGURED = True
def get_logger(name: str) -> logging.Logger:
return logging.getLogger(name)