Skip to content

Commit 8db67e0

Browse files
committed
refactor(src/preview.js): improve logging
1 parent 3ba8b4c commit 8db67e0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/preview.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import application from 'socket:application'
2+
import { inspect } from 'socket:util'
23

34
globalThis.RUNTIME_APPLICATION_ALLOW_MULTI_WINDOWS = true
45

56
const currentWindow = await application.getCurrentWindow()
6-
7-
const oldLog = console.log
8-
97
setTimeout(() => {
10-
globalThis.console.log = (...args) => {
11-
currentWindow.channel.postMessage({
12-
log: args
13-
})
8+
const consoleMethods = ['log', 'error', 'info', 'warn', 'debug']
9+
for (const method of consoleMethods) {
10+
const original = console[method]
11+
globalThis.console[method] = (...args) => {
12+
original.call(console, ...args)
13+
currentWindow.channel.postMessage({
14+
[method]: [inspect(...args)]
15+
})
16+
}
1417
}
1518
}, 2048)
1619

0 commit comments

Comments
 (0)