(toolName: string)
| 41 | } |
| 42 | |
| 43 | export function createLogCapture(toolName: string): LogCapture { |
| 44 | const logDir = resolveWritableLogDir(); |
| 45 | scheduleArtifactCreatedSweep(logDir); |
| 46 | const logPath = path.join(logDir.path, generateLogFileName(toolName)); |
| 47 | let fd: number | null = null; |
| 48 | |
| 49 | function ensureOpen(): number { |
| 50 | if (fd !== null) { |
| 51 | return fd; |
| 52 | } |
| 53 | fd = fs.openSync(logPath, 'wx'); |
| 54 | return fd; |
| 55 | } |
| 56 | |
| 57 | return { |
| 58 | write(chunk: string): void { |
| 59 | if (chunk.length === 0) { |
| 60 | return; |
| 61 | } |
| 62 | fs.writeSync(ensureOpen(), chunk); |
| 63 | }, |
| 64 | get path(): string { |
| 65 | return logPath; |
| 66 | }, |
| 67 | close(): void { |
| 68 | if (fd === null) { |
| 69 | return; |
| 70 | } |
| 71 | try { |
| 72 | fs.closeSync(fd); |
| 73 | } catch { |
| 74 | // already closed |
| 75 | } finally { |
| 76 | fd = null; |
| 77 | } |
| 78 | }, |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | export interface ParserDebugCapture { |
| 83 | addUnrecognizedLine(line: string): void; |
no test coverage detected