console¶
This module provides well known logging facilities for JavaScript programs. This module (partially) implements the CommonJS Console specification.
Console object¶
The Console object encapsulates all functionality in the console module in the form of a class. The module exports a default instance of this class though more can be created (which is rarely needed).
-
class
console.
Console
(stdout[, stderr])¶ Create an instance of a console object.
Arguments: - stdout – Object representing standard out. It must implement the same API as
io.File()
. - stderr – Analogous to stdout, but representing the standard error. If omitted stdout is used.
-
console.Console.console.Console.prototype.
assert
(expression[, message][, ...])¶ Simple assertion test using the assert module. The given expression is evaluated and if it’s falsey the given message is given with an
AssertionError
.console.assert(false, 'Whoops %s', 'Houston, we\'ve got a problem!'); // AssertionError: Whoops Houston, we've got a problem!
-
console.Console.console.Console.prototype.
log
()¶ Outpits the given data to
stdout
with a newline. Data is formatted usingutils.object.format()
.console.log('Hello %s! Here is a number: %d and an object: %j', 'sjs', 42, {foo: 'foo', bar: 'bar'}) // Hello sjs! Here is a number: 42 and an object: {"foo":"foo","bar":"bar"}
-
console.Console.console.Console.prototype.
info
()¶ Alias for
console.Console.prototype.log()
.
-
console.Console.console.Console.prototype.
error
()¶ Similar to
console.Console.prototype.log()
but it outputs tostderr
.
-
console.Console.console.Console.prototype.
warn
()¶ Alias for
console.Console.prototype.error()
.
-
console.Console.console.Console.prototype.
dir
(obj[, options])¶ Inspect the given object using :js:func:`` and print output to
stdout
.console.dir(console); // { log: [Function], // info: [Function], // warn: [Function], // error: [Function], // dir: [Function], // time: [Function], // timeEnd: [Function], // trace: [Function], // assert: [Function], // Console: [Function: Console] }
Note
The customInspect option is ignored if given.
-
console.Console.console.Console.prototype.
time
(label)¶
-
console.Console.console.Console.prototype.
timeEnd
(label)¶ Create a labeled timestamp. When
timeEnd
is called the time difference is computed and printed tostaout
.console.time('foo'); // (wait some time...) console.timeEnd('foo'); // foo: 6535.996ms
-
console.Console.console.Console.prototype.
trace
([message][, ...])¶ Prints a stack trace at the current position to
stderr
. If an optional message and formatting options are given the message is formatted usingutils.object.format()
.console.trace(); // Trace // at global (<repl>:1) preventsyield
- stdout – Object representing standard out. It must implement the same API as