better output for --debug

Massimo Melina committed Sep 28, 2025 at 12:09 UTC 2d975a82974f9f150eb3b1120238aed2e0faa197
1 file changed +14 -10
src/consoleLog.ts
+14 -10
@@ -5,19 +5,23 @@ import { argv } from './argv'
5
6 export const consoleLog: Array<{ ts: Date, k: string, msg: string }> = []
7 const f = argv.consoleFile ? createWriteStream(argv.consoleFile, 'utf-8') : null
8 -for (const k of ['log','warn','error']) {
8 +for (const k of ['log','warn','error','debug']) {
9 const original = console[k as 'log']
10 console[k as 'log'] = (...args: any[]) => {
11 const ts = new Date()
12 - const msg = safeJoin(args) // if args contains a symbol, join will throw
13 - const rec = { ts, k, msg }
14 - consoleLog.push(rec)
15 - if (consoleLog.length > 100_000) // limit to avoid infinite space
16 - consoleLog.splice(0, 1_000)
17 - events.emit('console', rec)
18 - f?.write(`${formatTimestamp(ts)} [${k}] ${msg}\n`)
19 - if (k !== 'log')
20 - args.unshift('!')
12 + if (k === 'debug')
13 + args.unshift('DBG')
14 + else {
15 + const msg = safeJoin(args) // if args contains a symbol, join will throw
16 + const rec = { ts, k, msg }
17 + consoleLog.push(rec)
18 + if (consoleLog.length > 100_000) // limit to avoid infinite space
19 + consoleLog.splice(0, 1_000)
20 + events.emit('console', rec)
21 + f?.write(`${formatTimestamp(ts)} [${k}] ${msg}\n`)
22 + if (k !== 'log')
23 + args.unshift('!')
24 + }
25 return original(formatTime(ts), ...args) // bundled nodejs doesn't have locales (and apparently uses en-US)
26 }
27 }