* Append a timestamped line to debug.log. * Synchronous to guarantee delivery in short-lived hook processes. * Silently fails — never throws, never recurses into log.
(level: string, msg: string)
| 73 | * Silently fails — never throws, never recurses into log. |
| 74 | */ |
| 75 | function writeToFile(level: string, msg: string): void { |
| 76 | if (_writing) return; // prevent recursion |
| 77 | _writing = true; |
| 78 | try { |
| 79 | ensureLogDir(); |
| 80 | maybeRotate(); |
| 81 | const ts = new Date().toISOString(); |
| 82 | const line = `${ts} [${level}] ${msg}\n`; |
| 83 | fs.appendFileSync(getLogFilePath(), line, 'utf-8'); |
| 84 | } catch { |
| 85 | // silent — file I/O must never disrupt the main flow |
| 86 | } finally { |
| 87 | _writing = false; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // ─── Test helpers (not exported in production API) ────── |
| 92 |
no test coverage detected