@samitouri / QOSami-HFS / commits / f6370252

print time in console

Massimo Melina committed May 30, 2024 at 08:54 UTC f63702528ab8e571176857d187f1267a6c901a96
1 file changed +3 -2
src/consoleLog.ts
+3 -2
@@ -4,11 +4,12 @@ export const consoleLog: Array<{ ts: Date, k: string, msg: string }> = []
4 for (const k of ['log','warn','error']) {
5 const original = console[k as 'log']
6 console[k as 'log'] = (...args: any[]) => {
7 - const rec = { ts: new Date(), k, msg: args.join(' ') }
7 + const ts = new Date()
8 + const rec = { ts, k, msg: args.join(' ') }
9 consoleLog.push(rec)
10 if (consoleLog.length > 100_000) // limit to avoid infinite space
11 consoleLog.splice(0, 1_000)
12 events.emit('console', rec)
12 - return original(...args)
13 + return original(ts.toLocaleTimeString('en-uk'), ...args)
14 }
15 }