(path: string)
| 83 | } |
| 84 | |
| 85 | function getLogWriter(path: string): JsonlWriter { |
| 86 | let writer = logWriters.get(path) |
| 87 | if (!writer) { |
| 88 | const dir = dirname(path) |
| 89 | writer = createJsonlWriter({ |
| 90 | // sync IO: called from sync context |
| 91 | writeFn: (content: string) => { |
| 92 | try { |
| 93 | // Happy-path: directory already exists |
| 94 | getFsImplementation().appendFileSync(path, content) |
| 95 | } catch { |
| 96 | // If any error occurs, assume it was due to missing directory |
| 97 | getFsImplementation().mkdirSync(dir) |
| 98 | // Retry appending |
| 99 | getFsImplementation().appendFileSync(path, content) |
| 100 | } |
| 101 | }, |
| 102 | flushIntervalMs: 1000, |
| 103 | maxBufferSize: 50, |
| 104 | }) |
| 105 | logWriters.set(path, writer) |
| 106 | registerCleanup(async () => writer?.dispose()) |
| 107 | } |
| 108 | return writer |
| 109 | } |
| 110 | |
| 111 | function appendToLog(path: string, message: object): void { |
| 112 | if (process.env.USER_TYPE !== 'ant') { |
no test coverage detected