(body: LogBody)
| 31 | * Format a single log line using local time (consistent with file name). |
| 32 | */ |
| 33 | export function formatLogLine(body: LogBody): string { |
| 34 | const d = new Date(body.ts); |
| 35 | const time = |
| 36 | `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ` + |
| 37 | `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad3(d.getMilliseconds())}`; |
| 38 | const argsStr = body.args |
| 39 | .map((a) => (a !== null && typeof a === 'object' ? JSON.stringify(a) : String(a))) |
| 40 | .join(' '); |
| 41 | return `${time} [${body.level.toUpperCase()}] [${body.tag}] ${argsStr}`; |
| 42 | } |
| 43 | |
| 44 | type FsLike = Pick<typeof fsType, 'appendFileSync' | 'existsSync' | 'mkdirSync'>; |
| 45 |
no test coverage detected