This commit is contained in:
aaron 2026-05-14 22:53:24 +08:00
parent 9d9983fb3f
commit 17a5828266
2 changed files with 29 additions and 5 deletions

View File

@ -565,17 +565,29 @@ class Handler(BaseHTTPRequestHandler):
def render_logs(self) -> None:
logs = self.list_logs()
alert_rows = "".join(
f"<tr><td>{row['id']}</td><td>{html.escape(row['symbol'])}</td><td>{html.escape(row['timeframe'])}</td><td>{html.escape(row['strategy'])}</td><td><span class='status'>{html.escape(row['status'])}</span></td><td>{html.escape(row['error'] or '')}</td><td>{row['created_at']}</td></tr>"
for row in logs["alerts"]
)
alert_rows = ""
for row in logs["alerts"]:
try:
raw_payload = json.dumps(json.loads(row["payload"]), ensure_ascii=False, indent=2)
except Exception:
raw_payload = row["payload"] or ""
alert_rows += f"""<tr>
<td>{row['id']}</td>
<td>{html.escape(row['symbol'])}</td>
<td>{html.escape(row['timeframe'])}</td>
<td>{html.escape(row['strategy'])}</td>
<td><span class='status'>{html.escape(row['status'])}</span></td>
<td>{html.escape(row['error'] or '')}</td>
<td>{row['created_at']}</td>
<td><details class="payload-details"><summary>查看</summary><pre>{html.escape(raw_payload)}</pre></details></td>
</tr>"""
delivery_rows = "".join(
f"<tr><td>{row['id']}</td><td>{row['alert_id']}</td><td>{html.escape(row['target_name'])}</td><td><span class='status'>{html.escape(row['status'])}</span></td><td>{row['attempts']}</td><td>{html.escape(str(row['response_code'] or ''))}</td><td>{html.escape(row['error'] or '')}</td><td>{html.escape(row['next_attempt_at'] or '')}</td></tr>"
for row in logs["deliveries"]
)
body = f"""<header><h1>日志</h1><p>最近 100 条 alert 和 200 条分发任务。</p></header>
<form method="post" action="/deliveries/retry"><button type="submit">处理到期重试</button></form>
<section><h2>Alert 日志</h2><table><thead><tr><th>ID</th><th>品种</th><th>周期</th><th>策略</th><th>状态</th><th>错误</th><th>时间</th></tr></thead><tbody>{alert_rows}</tbody></table></section>
<section><h2>Alert 日志</h2><table><thead><tr><th>ID</th><th>品种</th><th>周期</th><th>策略</th><th>状态</th><th>错误</th><th>时间</th><th>原始 Alert</th></tr></thead><tbody>{alert_rows}</tbody></table></section>
<section><h2>Delivery 日志</h2><table><thead><tr><th>ID</th><th>Alert</th><th>目标</th><th>状态</th><th>次数</th><th>HTTP</th><th>错误</th><th>下次重试</th></tr></thead><tbody>{delivery_rows}</tbody></table></section>"""
self.send_html("日志", body)

View File

@ -364,6 +364,18 @@ pre {
color: #f7f1e4;
}
.payload-details summary {
cursor: pointer;
color: var(--accent);
font-weight: 800;
}
.payload-details pre {
width: min(620px, 70vw);
max-height: 360px;
margin: 10px 0 0;
}
.inline {
display: inline;
}