Module console
This module provides functions to write on the standard error stream
stderr
for error logging and quick debugging. It’s similar to the console
object implemented in most web browsers.
Functions
assert (expression, msg...)
Tests that an expression is true and throws an AssertionError
exception if not. It uses the ECMAScript toBoolean()
convertion.
Example
>> var x = 10;
>> console.assert(x > 0, 'failed!'); // passes
>> console.assert(x < 0, 'failed!'); // fails
AssertionError: failed! at <stdin>:12
>> console.assert(false, 'failed!'); // fails
AssertionError: failed! at <stdin>:13
>> // passes; any Object expression is true
>> console.assert(new Boolean(false), 'failed!');
Parameters
null | expression | the expression to test |
... | msg... | one or more error messages |
dir (obj)
Prints a list of all properties of an object.
Example
>> var obj = { foo: "bar", baz: 12345 };
>> console.dir(obj);
{ foo: 'bar', baz: 12345 }
>> console.dir(global);
{ setTimeout: [Function], setInterval: [Function] }
Parameters
Object | obj | the object whose properties should be output |
error (msg...)
Logs a message with the visual "error" representation, including the file name and line number of the calling code.
Example
>> console.error('Hello World!');
[error] Hello World! (<stdin>:1)
>> console.error('A: %s, B: %s, C: %s', 'a', 'b', 'c');
[error] A: a, B: b, C: c (<stdin>:3)
>> console.error('Current nanoseconds: %d', java.lang.System.nanoTime());
[error] Current nanoseconds: 9228448561643 (<stdin>:5)
Parameters
null | msg... | one or more message arguments |
info (msg...)
Logs a message with the visual "info" representation, including the file name and line number of the calling code.
Example
>> console.info('Hello World!');
[info] Hello World! (<stdin>:1)
>> console.info('A: %s, B: %s, C: %s', 'a', 'b', 'c');
[info] A: a, B: b, C: c (<stdin>:3)
>> console.info('Current nanoseconds: %d', java.lang.System.nanoTime());
[info] Current nanoseconds: 9677228481391 (<stdin>:5)
Parameters
... | msg... | one or more message arguments |
log (msg...)
Logs a message to the console.
The first argument to log may be a string containing printf-like placeholders. Otherwise, multipel arguments will be concatenated separated by spaces.
Example
>> console.log('Hello World!');
Hello World!
>> console.log('A: %s, B: %s, C: %s', 'a', 'b', 'c');
A: a, B: b, C: c
>> console.log('Current nanoseconds: %d', java.lang.System.nanoTime());
Current nanoseconds: 9607196939209
Parameters
null | msg... | one or more message arguments |
time (name)
Creates a new timer under the given name. Call console.timeEnd(name)
with
the same name to stop the timer and log the time elapsed.
Example
>> console.time('timer-1');
>> // Wait some time ...
>> console.timeEnd('timer-1');
timer-1: 15769ms
Parameters
String | name | the timer name |
timeEnd (name)
Stops a timer created by a call to console.time(name)
and logs the time elapsed.
Example
>> console.time('timer-1');
>> // Wait some time ...
>> console.timeEnd('timer-1');
timer-1: 15769ms
Parameters
String | name | the timer name |
trace (msg...)
Prints a stack trace of JavaScript execution at the point where it is called.
Parameters
... | msg... | optional message arguments |
warn (msg...)
Logs a message with the visual "warn" representation, including the file name and line number of the calling code.
Example
>> console.warn('Hello World!');
[warn] Hello World! (<stdin>:1)
>> console.warn('A: %s, B: %s, C: %s', 'a', 'b', 'c');
[warn] A: a, B: b, C: c (<stdin>:3)
>> console.warn('Current nanoseconds: %d', java.lang.System.nanoTime());
[warn] Current nanoseconds: 9294672097821 (<stdin>:5)
Parameters
null | msg... | one or more message arguments |