- Flask 控制台:Cliproxy 巡检、批量补号、流水线、运行日志 - codex_stats_oauth_dir 支持统计 Cliproxy auth 目录 - 忽略 accounts/oauth、.venv、本地 DB/日志与 new.py Made-with: Cursor
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
"""维护台进程内任务日志(巡检 / 补号 / 与流水线摘要),写入 data/maintain_runtime.log"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
DEFAULT_PATH = REPO_ROOT / "maintain" / "data" / "maintain_runtime.log"
|
|
|
|
_logger: Optional[logging.Logger] = None
|
|
|
|
|
|
def runtime_log_path() -> Path:
|
|
return DEFAULT_PATH
|
|
|
|
|
|
def setup_runtime_logging() -> logging.Logger:
|
|
global _logger
|
|
if _logger is not None:
|
|
return _logger
|
|
DEFAULT_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
lg = logging.getLogger("maintain.runtime")
|
|
lg.setLevel(logging.INFO)
|
|
lg.propagate = False
|
|
if not lg.handlers:
|
|
fh = logging.FileHandler(DEFAULT_PATH, encoding="utf-8")
|
|
fh.setFormatter(
|
|
logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
|
|
)
|
|
lg.addHandler(fh)
|
|
_logger = lg
|
|
return lg
|
|
|
|
|
|
def rtlog() -> logging.Logger:
|
|
return setup_runtime_logging()
|