Skip to content

Commit

Permalink
console: add support for console.debug
Browse files Browse the repository at this point in the history
Adds the console.debug() method, alias for console.log(). This method is
exposed by V8 and was only available in inspector until now. Also adds
matching test and documentation.

PR-URL: #17033
Refs: #17004
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Tiriel authored and MylesBorins committed Dec 11, 2017
1 parent a12bc2d commit 40d4fee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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;


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

0 comments on commit 40d4fee

Please sign in to comment.