limit console log to avoid memory leak

Massimo Melina committed Apr 20, 2024 at 17:31 UTC ad7b6c437ba6abbdfc232fc33cd7487e777c89c3
1 file changed +2
src/consoleLog.ts
+2
@@ -6,6 +6,8 @@ for (const k of ['log','warn','error']) {
6 console[k as 'log'] = (...args: any[]) => {
7 const rec = { ts: new Date(), k, msg: args.join(' ') }
8 consoleLog.push(rec)
9 + if (consoleLog.length > 100_000) // limit to avoid infinite space
10 + consoleLog.splice(0, 1_000)
11 events.emit('console', rec)
12 return original(...args)
13 }