summaryrefslogtreecommitdiff
path: root/lib/util.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-03-06 12:54:12 +0100
committerJoyee Cheung <joyeec9h3@gmail.com>2019-03-08 13:57:38 +0100
commitb05fd4baa87886674721101eaf38b75716037891 (patch)
tree944d9db74ba3b14a9d74f3be081cc1351c338bb9 /lib/util.js
parent687f30467b67db9f39334cd19faa484c20a4ab06 (diff)
downloadandroid-node-v8-b05fd4baa87886674721101eaf38b75716037891.tar.gz
android-node-v8-b05fd4baa87886674721101eaf38b75716037891.tar.bz2
android-node-v8-b05fd4baa87886674721101eaf38b75716037891.zip
lib: explicitly initialize debuglog during bootstrap
This patch splits the implementation of util.debuglog into a separate file and explicitly initialize it during pre-execution since the initialization depends on environment variables. Also delays the call to `debuglog` in modules that are loaded during bootstrap to make sure we only access the environment variable during pre-execution. PR-URL: https://github.com/nodejs/node/pull/26468 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/util.js')
-rw-r--r--lib/util.js40
1 files changed, 1 insertions, 39 deletions
diff --git a/lib/util.js b/lib/util.js
index 98e41e5a37..8c4c0cb098 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -27,6 +27,7 @@ const {
formatWithOptions,
inspect
} = require('internal/util/inspect');
+const { debuglog } = require('internal/util/debuglog');
const {
ERR_FALSY_VALUE_REJECTION,
ERR_INVALID_ARG_TYPE,
@@ -52,45 +53,6 @@ const objectToString = uncurryThis(Object.prototype.toString);
let internalDeepEqual;
-const debugs = {};
-let debugEnvRegex = /^$/;
-if (process.env.NODE_DEBUG) {
- let debugEnv = process.env.NODE_DEBUG;
- debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&')
- .replace(/\*/g, '.*')
- .replace(/,/g, '$|^')
- .toUpperCase();
- debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
-}
-
-// Emits warning when user sets
-// NODE_DEBUG=http or NODE_DEBUG=http2.
-function emitWarningIfNeeded(set) {
- if ('HTTP' === set || 'HTTP2' === set) {
- process.emitWarning('Setting the NODE_DEBUG environment variable ' +
- 'to \'' + set.toLowerCase() + '\' can expose sensitive ' +
- 'data (such as passwords, tokens and authentication headers) ' +
- 'in the resulting log.');
- }
-}
-
-function debuglog(set) {
- set = set.toUpperCase();
- if (!debugs[set]) {
- if (debugEnvRegex.test(set)) {
- const pid = process.pid;
- emitWarningIfNeeded(set);
- debugs[set] = function debug() {
- const msg = exports.format.apply(exports, arguments);
- console.error('%s %d: %s', set, pid, msg);
- };
- } else {
- debugs[set] = function debug() {};
- }
- }
- return debugs[set];
-}
-
function isBoolean(arg) {
return typeof arg === 'boolean';
}