MCPcopy
hub / github.com/7836246/cursor2api / persistRequest

Function persistRequest

src/logger.ts:498–526  ·  view source on GitHub ↗

将已完成的请求写入日志文件和/或 SQLite

(summary: RequestSummary, payload: RequestPayload)

Source from the content-addressed store, hash-verified

496
497/** 将已完成的请求写入日志文件和/或 SQLite */
498function persistRequest(summary: RequestSummary, payload: RequestPayload): void {
499 // ---- 原有 JSONL 文件方式(保持不变)----
500 const filepath = getLogFilePath();
501 if (filepath) {
502 try {
503 ensureLogDir();
504 const persistMode = getPersistMode();
505 const persistedPayload = persistMode === 'full'
506 ? payload
507 : persistMode === 'summary'
508 ? buildSummaryPayload(summary, payload)
509 : compactPayloadForDisk(summary, payload);
510 const record = { timestamp: Date.now(), summary, payload: persistedPayload };
511 appendFileSync(filepath, JSON.stringify(record) + '\n', 'utf-8');
512 } catch (e) {
513 console.warn('[Logger] 写入日志文件失败:', e);
514 }
515 }
516
517 // ---- 新增 SQLite 方式 ----
518 const cfg = getConfig();
519 if (cfg.logging?.db_enabled) {
520 try {
521 dbInsertRequest(summary, payload);
522 } catch (e) {
523 console.warn('[Logger] 写入 SQLite 失败:', e);
524 }
525 }
526}
527
528/** 启动时从日志文件和/或 SQLite 加载历史记录 */
529export function loadLogsFromFiles(): void {

Callers 3

completeMethod · 0.85
interceptedMethod · 0.85
failMethod · 0.85

Calls 8

getConfigFunction · 0.90
dbInsertRequestFunction · 0.90
getLogFilePathFunction · 0.85
ensureLogDirFunction · 0.85
getPersistModeFunction · 0.85
buildSummaryPayloadFunction · 0.85
compactPayloadForDiskFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected