/** * Logger — MCP Dashboard 的日志基础层 * * 双写 JSONL 文件 + stderr,缓冲批量刷盘,tool 配对追踪, * 敏感数据清洗,按日切割 + 保留天数清理。 */ import type { Server } from "@modelcontextprotocol/server"; export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; export interface LogEntry { v: 1; ts: string; level: LogLevel; module: string; msg: string; tool?: string; duration_ms?: number; error?: string; type?: 'tool_start' | 'tool_end' | 'rotation'; call_id?: string; meta?: Record; } export interface LoggerOptions { logDir?: string; bufferMs?: number; bufferMax?: number; maxRetentionDays?: number; } export interface Logger { debug(module: string, msg: string, meta?: Record): void; info(module: string, msg: string, meta?: Record): void; warn(module: string, msg: string, meta?: Record): void; error(module: string, msg: string, meta?: Record): void; toolStart(tool: string, args?: Record): string; toolEnd(callId: string, tool: string, durationMs: number, error?: string): void; flush(): void; pendingCount(): number; close(): void; } /** 确定日志目录 — XDG 标准路径 */ export declare function resolveLogDir(override?: string): string; /** Sanitize msg — 截断 + 敏感 key=value 值脱敏(P2-10) */ export declare function sanitizeMsg(msg: string): string; type RequestLogFn = (level: string, data: unknown, logger?: string) => Promise; /** * P1-7: 包裹器,在工具调用期间设置 per-request logLevel,执行完(含抛错)复位。 * ToolDispatcher.handleCall 提取 _meta['io.modelcontextprotocol/logLevel'] 后用此包裹工具执行。 * emitToClient 读 _currentRequestLogLevel 决定是否过滤。 * * 同步版:用于同步代码块。工具调用是 async,用 withRequestLogLevelAsync。 */ export declare function withRequestLogLevel(level: LogLevel | 'off' | null, fn: () => T): T; /** * P1-7: async 版包裹器,await 完成后才复位(同步版会在 Promise resolve 前就复位)。 * ToolDispatcher.executeToolCall 用此包裹 targetMod.handleTool(await)。 */ export declare function withRequestLogLevelAsync(level: LogLevel | 'off' | null, fn: () => Promise): Promise; /** 读当前 per-request logLevel(测试用,工具一般不直接读)。 */ export declare function getCurrentRequestLogLevel(): LogLevel | 'off' | null; /** * P1-3 完整推进: async 包裹器, 在工具调用期间注入 SDK 官方 per-request log 函数。 * ToolDispatcher.handleCall 从 srvCtx.mcpReq.log 提取后用此包裹工具执行链。 * emitToClient 优先用 _requestLogFn(SDK 自动过滤), 无它时降级到自管 _currentRequestLogLevel。 * finally 保证复位(含抛错)。 */ export declare function withRequestLogFn(logFn: RequestLogFn | null, fn: () => Promise): Promise; /** 读当前 per-request log 函数(测试用)。 */ export declare function getCurrentRequestLogFn(): RequestLogFn | null; /** 注入 MCP Server 实例(GodotServer 构造时调);null 清除(close/测试隔离) */ export declare function setLoggerServer(server: Server | null): void; /** 标记 client 是否已完成 initialize(oninitialized 时设 true);未就绪不发,避免 SDK 报错 */ export declare function setLoggerClientReady(ready: boolean): void; export declare function getLogger(opts?: LoggerOptions): Logger; export declare function resetLogger(): void; export {};