--consoleFile
Massimo Melina committed
Dec 19, 2024 at 16:42 UTC
1fca2a7d0fe2197393c879876700309985becd92
2 files changed
+8
-2
README.md
+1
@@ -132,6 +132,7 @@ If your language is missing, please consider [translating yourself](https://gith
132
- Right-click on "check for updates" will let you input a URL of a version to install
133
- Shift+click on a file will show & play
134
- Type the name of a file/folder to focus it, and ctrl+backspace to go to parent folder
135
+- `--consoleFile PATH` will output all stdout and stderr also to a file
136
137
## Contribute
138
src/consoleLog.ts
+7
-2
@@ -1,16 +1,21 @@
1
import events from './events'
2
-import { formatTime } from './cross'
2
+import { formatTime, formatTimestamp } from './cross'
3
+import { createWriteStream } from 'fs'
4
+import { argv } from './const'
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']) {
9
const original = console[k as 'log']
10
console[k as 'log'] = (...args: any[]) => {
11
const ts = new Date()
9
- const rec = { ts, k, msg: args.join(' ') }
12
+ const msg = args.join(' ')
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
return original(formatTime(ts), ...args) // bundled nodejs doesn't have locales (and apparently uses en-US)
20
}
21
}