Console

console~ Console

new Console()

Do not create directly, use console instance from global.

 console.debug('Yeh!');

Methods

log()

Output to log with log level Info. Internally use util.format for create output, so format chars can be used:

  • %s - String.
  • %d - Number (both integer and float).
  • %j - JSON.
  • % - single percent sign ('%'). This does not consume an argument.

    console.log('%s is a %s usually with weight less then %dgr', 'apple', 'fruit', 100); //Will output "apple is a fruit usually with weight less then 100gr"

    console.log('apple', 'fruit', 100); //will output "apple fruit 100"

    console.log('the object JSON is %j', {a: 12, b: {inner: 11}}); // will output a JSON object instead of [object Object]

Arguments:
  1. ... (*)

debug()

Output to log with log level Debug. In case process.isDebug is false - do nothing
Arguments:
  1. ... (*)

info()

Output to log with log level Info (alias for console.log)
Arguments:
  1. ... (*)

warn()

Output to log with log level Warning. In case of OS console echo output to stderr
Arguments:
  1. ... (*)

error()

Output to log with log level Error. In case of OS console echo output to stderr
Arguments:
  1. ... (*)

dir(object)

Uses util.inspect on obj and prints resulting string to stdout.
Arguments:
  1. object (Object)

time(label)

Mark a time.
Arguments:
  1. label (String)

timeEnd(label)

Finish timer, record output
Arguments:
  1. label (string)
Example
console.time('100-elements');
       for (var i = 0; i < 100; i++) {
        ;
     }
     console.timeEnd('100-elements');

assert(expression)

Similar to assert#ok, but the error message is formatted as util.format(message...).
Arguments:
  1. expression