Skip to content

util: avoid run debug when enabled is false #57494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function lazyUtilColors() {
return utilColors;
}

function debuglogImpl(enabled, set, args) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args was never used

function debuglogImpl(enabled, set) {
if (debugImpls[set] === undefined) {
if (enabled) {
const pid = process.pid;
Expand Down Expand Up @@ -109,6 +109,8 @@ function debuglog(set, cb) {
return enabled;
};
const logger = (...args) => {
// Improve performance when debug is disabled, avoid calling `new SafeArrayIterator(args)`
if (enabled === false) return;
switch (args.length) {
case 1: return debug(args[0]);
case 2: return debug(args[0], args[1]);
Expand Down
Loading