import fs from 'node:fs'; const LOG_FILE = '/tmp/proxy.jsonl'; export interface LogEntry { time: string; method: string; path: string; status: number; duration: number; stream?: boolean; error?: string; provider?: string; } export function log(entry: LogEntry): void { try { const logLine = JSON.stringify(entry) + '\n'; fs.appendFileSync(LOG_FILE, logLine, 'utf-8'); } catch (e) { console.error('写入日志失败:', e); } } export function createLogEntry( method: string, path: string, status: number, duration: number, options?: { stream?: boolean; error?: string; provider?: string } ): LogEntry { return { time: new Date().toISOString(), method, path, status, duration, ...options, }; }