Files
DinQuant/backend_api_python/app/utils/strategy_runtime_logs.py
T
Dinger 8563e4ea53 v3.0.1
Signed-off-by: Dinger <quantdinger@gmail.com>
2026-04-07 22:47:07 +08:00

30 lines
938 B
Python

"""Persist strategy runtime lines for the strategy management UI (`qd_strategy_logs`)."""
from __future__ import annotations
from app.utils.db import get_db_connection
from app.utils.logger import get_logger
logger = get_logger(__name__)
def append_strategy_log(strategy_id: int, level: str, message: str) -> None:
"""Best-effort insert; never raises to caller."""
try:
sid = int(strategy_id)
lv = (level or "info").strip().lower()[:20]
msg = str(message or "").strip()
if not msg:
return
msg = msg[:8000]
with get_db_connection() as db:
cur = db.cursor()
cur.execute(
"INSERT INTO qd_strategy_logs (strategy_id, level, message) VALUES (?, ?, ?)",
(sid, lv, msg),
)
db.commit()
cur.close()
except Exception as e:
logger.debug("append_strategy_log skip: %s", e)