SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
938 B · 15 lines typescript
Raw Blame History
1// Minimal sanitized request logger for the TypeScript examples (mirrors scripts/live.py::log_request).2// Appends one JSON line to reports/live-requests.jsonl; never writes keys (masks sk-… patterns defensively).3import { appendFileSync, mkdirSync } from "node:fs";4import { dirname, resolve } from "node:path";5import { fileURLToPath } from "node:url";67const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");8const LOG = resolve(ROOT, "reports/live-requests.jsonl");910export function logRequest(provider: string, method: string, path: string, status: number, estCostUsd = 0, note = ""): void {11  mkdirSync(dirname(LOG), { recursive: true });12  const safe = note.replace(/sk-(ant-)?[A-Za-z0-9_-]{8,}/g, "sk-***REDACTED***").slice(0, 300);13  appendFileSync(LOG, JSON.stringify({ ts: new Date().toISOString().replace(/\.\d+Z$/, "Z"), provider, method, path, status, est_cost_usd: estCostUsd, note: safe }) + "\n");14}15