Skip to content

Commit

Permalink
fixup: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Mar 7, 2022
1 parent 8a363f2 commit 3851a8f
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,6 @@ const {
StringPrototypeToLowerCase,
StringPrototypeToUpperCase,
} = primordials;
const wrapDebugLog = (set, logger) => {
const { hasInspector } = internalBinding('config');
if (hasInspector) {
const { consoleCall } = internalBinding('inspector');
const pid = process.pid;
return (...args) => {
const inspect = require('internal/util/inspector');
return consoleCall((maybeFmt, ...args) => {
if (typeof maybeFmt === 'string') {
inspect.consoleFromVM.debug(`%s %i: ${maybeFmt}`, set, pid, ...args);
} else {
inspect.consoleFromVM.debug('%s %i:', set, pid, maybeFmt, ...args);
}
}, logger, ...args);
};
}
return logger;
};

const { inspect, format, formatWithOptions } = require('internal/util/inspect');

// `debugImpls` and `testEnabled` are deliberately not initialized so any call
// to `debuglog()` before `initializeDebugEnv()` is called will throw.
Expand Down Expand Up @@ -69,12 +49,15 @@ function debuglogImpl(enabled, set) {
if (enabled) {
const pid = process.pid;
emitWarningIfNeeded(set);
debugImpls[set] = wrapDebugLog(set, function debug(...args) {
const colors = process.stderr.hasColors && process.stderr.hasColors();
const msg = formatWithOptions({ colors }, ...args);
const coloredPID = inspect(pid, { colors });
process.stderr.write(format('%s %s: %s\n', set, coloredPID, msg));
});
debugImpls[set] = function debug(maybeFmt, ...args) {
if (typeof maybeFmt === 'string') {
// eslint-disable-next-line
console.debug(`%s %i: ${maybeFmt}`, set, pid, ...args);
} else {
// eslint-disable-next-line
console.debug('%s %i:', set, pid, maybeFmt, ...args);
}
};
} else {
debugImpls[set] = noop;
}
Expand Down

0 comments on commit 3851a8f

Please sign in to comment.