(level: LogLevel, args: unknown[])
| 23 | } |
| 24 | |
| 25 | export function formatLogEntry(level: LogLevel, args: unknown[]): string { |
| 26 | const timestamp = new Date().toISOString(); |
| 27 | const body = args |
| 28 | .map((arg) => { |
| 29 | if (arg instanceof Error) { |
| 30 | return arg.stack ?? `${arg.name}: ${arg.message}`; |
| 31 | } |
| 32 | if (typeof arg === "string") return arg; |
| 33 | return inspect(arg, { depth: 4, breakLength: 120 }); |
| 34 | }) |
| 35 | .join(" "); |
| 36 | return `${timestamp} [${level}] ${body}`; |
| 37 | } |
| 38 | |
| 39 | // Open the log file in append mode. The fd survives across writes so |
| 40 | // we don't pay an open/close per line. Throws if the path's directory |
no outgoing calls
no test coverage detected