Files
claude-api-proxy/src/logger.ts
D8D Developer f6f8af6583 feat: 添加 OpenAI API 代理支持
- 新增 /openai/v1/* 路由代理 OpenAI API
- 添加 OPENAI_BASE_URL 环境变量支持
- 更新日志记录支持 provider 字段

使用方式:
- Claude API: /v1/*
- OpenAI API: /openai/v1/*

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-03-20 14:53:45 +00:00

41 lines
769 B
TypeScript

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,
};
}