Skip to content

Commit 16641f7

Browse files
committed
console: Add common aliases for console methods
- add common aliases as per following spec - https://github.com/DeveloperToolsWG/console-object/blob/master/api.md
1 parent a3b238a commit 16641f7

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

doc/api/console.markdown

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ is used on each argument. See [util.format()][] for more information.
4848

4949
Same as `console.log`.
5050

51+
### console.debug(object [,object, ...])
52+
53+
Same as `console.log`.
54+
5155
### console.error([data][, ...])
5256

5357
Same as `console.log` but prints to stderr.
@@ -56,6 +60,10 @@ Same as `console.log` but prints to stderr.
5660

5761
Same as `console.error`.
5862

63+
### console.exception(object [, object, ...])
64+
65+
Same as `console.error`.
66+
5967
### console.dir(obj[, options])
6068

6169
Uses `util.inspect` on `obj` and prints resulting string to stdout. This function

lib/console.js

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Console.prototype.log = function() {
4040
Console.prototype.info = Console.prototype.log;
4141

4242

43+
Console.prototype.debug = Console.prototype.log;
44+
45+
4346
Console.prototype.warn = function() {
4447
this._stderr.write(util.format.apply(this, arguments) + '\n');
4548
};
@@ -48,6 +51,9 @@ Console.prototype.warn = function() {
4851
Console.prototype.error = Console.prototype.warn;
4952

5053

54+
Console.prototype.exception = Console.prototype.warn;
55+
56+
5157
Console.prototype.dir = function(object, options) {
5258
this._stdout.write(util.inspect(object, util._extend({
5359
customInspect: false

test/parallel/test-console-instance.js

+9
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,19 @@ assert(!called);
3636
c.log('test');
3737
assert(called);
3838

39+
assert.equal(Console.prototype.log, Console.prototype.debug);
40+
assert.equal(c.log('test'), c.debug('test'));
41+
3942
called = false;
4043
c.error('test');
4144
assert(called);
4245

46+
assert.equal(Console.prototype.error, Console.prototype.warn);
47+
assert.equal(c.error('test'), c.warn('test'));
48+
49+
assert.equal(Console.prototype.exception, Console.prototype.warn);
50+
assert.equal(c.exception('test'), c.warn('test'));
51+
4352
out.write = function(d) {
4453
assert.equal('{ foo: 1 }\n', d);
4554
called = true;

0 commit comments

Comments
 (0)