(scope: string, message: string, detail?: unknown)
| 60 | } |
| 61 | |
| 62 | export function runtimeDebug(scope: string, message: string, detail?: unknown): void { |
| 63 | try { |
| 64 | ensureDebugDir(); |
| 65 | const time = new Date().toISOString(); |
| 66 | const suffix = detail === undefined ? '' : ` | ${detailToString(detail)}`; |
| 67 | const formatted = `${time} pid=${process.pid} [${scope}] ${message} | ${runtimeMemorySummary()}${suffix}`; |
| 68 | // Rotate log if it exceeds the size limit |
| 69 | try { |
| 70 | const stat = fs.statSync(DEBUG_LOG_FILE); |
| 71 | if (stat.size > MAX_LOG_SIZE) { |
| 72 | fs.truncateSync(DEBUG_LOG_FILE, 0); |
| 73 | } |
| 74 | } catch { /* file doesn't exist yet — that's fine */ } |
| 75 | fs.appendFileSync(DEBUG_LOG_FILE, formatted + '\n', 'utf-8'); |
| 76 | if (outputHook) outputHook(formatted); |
| 77 | } catch { |
| 78 | // Best-effort only. |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | export function installRuntimeDebugHooks(scope = 'extension-host'): void { |
| 83 | const globalObj = globalThis as Record<string, unknown>; |
no test coverage detected