Skip to content
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

console: add support for console.debug method #17033

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ undefined
>
```

### console.debug(data[, ...args])
<!-- YAML
added: v8.0.0
-->
* `data` {any}
* `...args` {any}

The `console.debug()` function is an alias for [`console.log()`][].

### console.dir(obj[, options])
<!-- YAML
added: v0.1.101
Expand Down
3 changes: 3 additions & 0 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ Console.prototype.log = function log(...args) {
};


Console.prototype.debug = Console.prototype.log;
Copy link
Member

Choose a reason for hiding this comment

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

Per MDN,

Starting with Chromium 58 this method only appears in Chromium browser consoles when level "Verbose" is selected.

Thus for consistency, I don't think we should show debug logs by default, per default. Instead we could perhaps only display debug logs when an environment variable is specified. @nodejs/collaborators thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I like having debug be conditional upon some flag. Having it just be an alias doesn't seem that appealing.

Copy link
Member

@Trott Trott Nov 15, 2017

Choose a reason for hiding this comment

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

Firefox and I believe every other major browser do not require a flag for console.debug() to display. I'm not sure we should follow Chrome's practice on this one. (I'm not sure we shouldn't either. I guess it kinda makes sense in Node.js for debug() to be conditional. So, maybe?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that choosing t to follow Chrome on this feature would mean getting a bit too much opinionated, and I don't think we should. As you said, no other browser makes this choice.
The choice to restrain visibility of the debug should be made by the users IMHO, and Node should only provide the method.

Copy link
Member

Choose a reason for hiding this comment

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

I’m good with this. If they want to, anybody can override this method in their App, globally, and possibly depending on environment variables…



Console.prototype.info = Console.prototype.log;


Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ console.log('%s %s', 'foo', 'bar', 'hop');
console.log({ slashes: '\\\\' });
console.log(custom_inspect);

// test console.debug() goes to stdout
console.debug('foo');
console.debug('foo', 'bar');
console.debug('%s %s', 'foo', 'bar', 'hop');
console.debug({ slashes: '\\\\' });
console.debug(custom_inspect);

// test console.info() goes to stdout
console.info('foo');
console.info('foo', 'bar');
Expand Down Expand Up @@ -154,6 +161,10 @@ for (const expected of expectedStrings) {
assert.strictEqual(errStrings.shift(), `${expected}\n`);
}

for (const expected of expectedStrings) {
assert.strictEqual(strings.shift(), `${expected}\n`);
}

assert.strictEqual(strings.shift(),
"{ foo: 'bar', inspect: [Function: inspect] }\n");
assert.strictEqual(strings.shift(),
Expand Down