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 common aliases for console methods #3486

Closed
wants to merge 1 commit 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
8 changes: 8 additions & 0 deletions doc/api/console.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ is used on each argument. See [util.format()][] for more information.

Same as `console.log`.

### console.debug(object [,object, ...])

Same as `console.log`.

### console.error([data][, ...])

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

Same as `console.error`.

### console.exception(object [, object, ...])

Same as `console.error`.

### console.dir(obj[, options])

Uses `util.inspect` on `obj` and prints resulting string to stdout. This function
Expand Down
6 changes: 6 additions & 0 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Console.prototype.log = function() {
Console.prototype.info = Console.prototype.log;


Console.prototype.debug = Console.prototype.log;


Console.prototype.warn = function() {
this._stderr.write(util.format.apply(this, arguments) + '\n');
};
Expand All @@ -48,6 +51,9 @@ Console.prototype.warn = function() {
Console.prototype.error = Console.prototype.warn;


Console.prototype.exception = Console.prototype.warn;


Console.prototype.dir = function(object, options) {
this._stdout.write(util.inspect(object, util._extend({
customInspect: false
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-console-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ assert(!called);
c.log('test');
assert(called);

assert.equal(Console.prototype.log, Console.prototype.debug);
assert.equal(c.log('test'), c.debug('test'));

called = false;
c.error('test');
assert(called);

assert.equal(Console.prototype.error, Console.prototype.warn);
assert.equal(c.error('test'), c.warn('test'));

assert.equal(Console.prototype.exception, Console.prototype.warn);
assert.equal(c.exception('test'), c.warn('test'));

out.write = function(d) {
assert.equal('{ foo: 1 }\n', d);
called = true;
Expand Down