Skip to content

Commit 0ab6141

Browse files
committed
Fix loggers printing of error objects
1 parent c102acc commit 0ab6141

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

registry/lib/logger.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ const LOG_SYMBOLS = /*@__PURE__*/ (() => {
5555
return new Proxy(target, handler)
5656
})()
5757

58+
const boundConsoleMethods = new Map(
59+
['debug', 'dir', 'dirxml', 'error', 'info', 'log', 'trace', 'warn'].map(n => [
60+
n,
61+
console[n].bind(console)
62+
])
63+
)
64+
5865
const privateConsole = new WeakMap()
5966

6067
const symbolTypeToMethodName = {
@@ -69,12 +76,20 @@ class Logger {
6976
static LOG_SYMBOLS = LOG_SYMBOLS
7077

7178
constructor(...args) {
72-
privateConsole.set(
73-
this,
74-
args.length
75-
? constructConsole(...args)
76-
: constructConsole({ stdout: process.stdout, stderr: process.stderr })
77-
)
79+
if (args.length) {
80+
privateConsole.set(this, constructConsole(...args))
81+
} else {
82+
// Create a new console that acts like the builtin one so that it will
83+
// work with Node's --frozen-intrinsics flag.
84+
const newConsole = constructConsole({
85+
stdout: process.stdout,
86+
stderr: process.stderr
87+
})
88+
for (const { 0: key, 1: method } of boundConsoleMethods) {
89+
newConsole[key] = method
90+
}
91+
privateConsole.set(this, newConsole)
92+
}
7893
}
7994

8095
#symbolApply(symbolType, args) {

0 commit comments

Comments
 (0)