lib: explicitly initialize debuglog during bootstrap · nodejs/node@9ce08c8 (original) (raw)
`@@ -27,6 +27,7 @@ const {
`
27
27
` formatWithOptions,
`
28
28
` inspect
`
29
29
`} = require('internal/util/inspect');
`
``
30
`+
const { debuglog } = require('internal/util/debuglog');
`
30
31
`const {
`
31
32
`ERR_FALSY_VALUE_REJECTION,
`
32
33
`ERR_INVALID_ARG_TYPE,
`
`@@ -52,45 +53,6 @@ const objectToString = uncurryThis(Object.prototype.toString);
`
52
53
``
53
54
`let internalDeepEqual;
`
54
55
``
55
``
`-
const debugs = {};
`
56
``
`-
let debugEnvRegex = /^$/;
`
57
``
`-
if (process.env.NODE_DEBUG) {
`
58
``
`-
let debugEnv = process.env.NODE_DEBUG;
`
59
``
`-
debugEnv = debugEnv.replace(/[|\{}()[]^$+?.]/g, '\$&')
`
60
``
`-
.replace(/*/g, '.*')
`
61
``
`-
.replace(/,/g, '$|^')
`
62
``
`-
.toUpperCase();
`
63
``
`` -
debugEnvRegex = new RegExp(^${debugEnv}$
, 'i');
``
64
``
`-
}
`
65
``
-
66
``
`-
// Emits warning when user sets
`
67
``
`-
// NODE_DEBUG=http or NODE_DEBUG=http2.
`
68
``
`-
function emitWarningIfNeeded(set) {
`
69
``
`-
if ('HTTP' === set || 'HTTP2' === set) {
`
70
``
`-
process.emitWarning('Setting the NODE_DEBUG environment variable ' +
`
71
``
`-
'to '' + set.toLowerCase() + '' can expose sensitive ' +
`
72
``
`-
'data (such as passwords, tokens and authentication headers) ' +
`
73
``
`-
'in the resulting log.');
`
74
``
`-
}
`
75
``
`-
}
`
76
``
-
77
``
`-
function debuglog(set) {
`
78
``
`-
set = set.toUpperCase();
`
79
``
`-
if (!debugs[set]) {
`
80
``
`-
if (debugEnvRegex.test(set)) {
`
81
``
`-
const pid = process.pid;
`
82
``
`-
emitWarningIfNeeded(set);
`
83
``
`-
debugs[set] = function debug() {
`
84
``
`-
const msg = exports.format.apply(exports, arguments);
`
85
``
`-
console.error('%s %d: %s', set, pid, msg);
`
86
``
`-
};
`
87
``
`-
} else {
`
88
``
`-
debugs[set] = function debug() {};
`
89
``
`-
}
`
90
``
`-
}
`
91
``
`-
return debugs[set];
`
92
``
`-
}
`
93
``
-
94
56
`function isBoolean(arg) {
`
95
57
`return typeof arg === 'boolean';
`
96
58
`}
`