{ "source": "doc/api/console.markdown", "modules": [ { "textRaw": "Console", "name": "console", "stability": 2, "stabilityText": "Stable", "desc": "

The module defines a Console class and exports a console object.\n\n

\n

The console object is a special instance of Console whose output is\nsent to stdout or stderr.\n\n

\n

For ease of use, console is defined as a global object and can be used\ndirectly without require.\n\n

\n", "globals": [ { "textRaw": "console", "name": "console", "type": "global", "desc": "

For printing to stdout and stderr. Similar to the console object functions\nprovided by most web browsers, here the output is sent to stdout or stderr.\n\n

\n

The console functions are synchronous when the destination is a terminal or\na file (to avoid lost messages in case of premature exit) and asynchronous\nwhen it's a pipe (to avoid blocking for long periods of time).\n\n

\n

That is, in the following example, stdout is non-blocking while stderr\nis blocking:\n\n

\n
$ node script.js 2> error.log | tee info.log
\n

In daily use, the blocking/non-blocking dichotomy is not something you\nshould worry about unless you log huge amounts of data.\n\n\n

\n", "methods": [ { "textRaw": "console.log([data][, ...])", "type": "method", "name": "log", "desc": "

Prints to stdout with newline. This function can take multiple arguments in a\nprintf()-like way. Example:\n\n

\n
var count = 5;\nconsole.log('count: %d', count);\n// prints 'count: 5'
\n

If formatting elements are not found in the first string then util.inspect\nis used on each argument. See [util.format()][] for more information.\n\n

\n", "signatures": [ { "params": [ { "name": "data", "optional": true }, { "name": "...", "optional": true } ] } ] }, { "textRaw": "console.info([data][, ...])", "type": "method", "name": "info", "desc": "

Same as console.log.\n\n

\n", "signatures": [ { "params": [ { "name": "data", "optional": true }, { "name": "...", "optional": true } ] } ] }, { "textRaw": "console.error([data][, ...])", "type": "method", "name": "error", "desc": "

Same as console.log but prints to stderr.\n\n

\n", "signatures": [ { "params": [ { "name": "data", "optional": true }, { "name": "...", "optional": true } ] } ] }, { "textRaw": "console.warn([data][, ...])", "type": "method", "name": "warn", "desc": "

Same as console.error.\n\n

\n", "signatures": [ { "params": [ { "name": "data", "optional": true }, { "name": "...", "optional": true } ] } ] }, { "textRaw": "console.dir(obj[, options])", "type": "method", "name": "dir", "desc": "

Uses util.inspect on obj and prints resulting string to stdout. This function\nbypasses any custom inspect() function on obj. An optional options object\nmay be passed that alters certain aspects of the formatted string:\n\n

\n\n", "signatures": [ { "params": [ { "name": "obj" }, { "name": "options", "optional": true } ] } ] }, { "textRaw": "console.time(timerName)", "type": "method", "name": "time", "desc": "

Starts a timer that can be used to compute the duration of an operation. Timers\nare identified by a unique name. Use the same name when you call\nconsole.timeEnd() to stop the timer and\noutput the elapsed time in milliseconds. Timer durations are accurate to the\nsub-millisecond.\n\n

\n", "signatures": [ { "params": [ { "name": "timerName" } ] } ] }, { "textRaw": "console.timeEnd(timerName)", "type": "method", "name": "timeEnd", "desc": "

Stops a timer that was previously started by calling\nconsole.time() and prints the result to the\nconsole.\n\n

\n

Example:\n\n

\n
console.time('100-elements');\nfor (var i = 0; i < 100; i++) {\n  ;\n}\nconsole.timeEnd('100-elements');\n// prints 100-elements: 225.438ms
\n", "signatures": [ { "params": [ { "name": "timerName" } ] } ] }, { "textRaw": "console.trace(message[, ...])", "type": "method", "name": "trace", "desc": "

Print to stderr 'Trace :', followed by the formatted message and stack trace\nto the current position.\n\n

\n", "signatures": [ { "params": [ { "name": "message" }, { "name": "...", "optional": true } ] } ] }, { "textRaw": "console.assert(value[, message][, ...])", "type": "method", "name": "assert", "desc": "

Similar to [assert.ok()][], but the error message is formatted as\nutil.format(message...).\n\n

\n", "signatures": [ { "params": [ { "name": "value" }, { "name": "message", "optional": true }, { "name": "...", "optional": true } ] } ] } ] } ], "classes": [ { "textRaw": "Class: Console", "type": "class", "name": "Console", "desc": "

Use require('console').Console or console.Console to access this class.\n\n

\n
var Console = require('console').Console;\nvar Console = console.Console;
\n

You can use Console class to custom simple logger like console, but with\ndifferent output streams.\n\n

\n", "signatures": [ { "params": [ { "name": "stdout" }, { "name": "stderr", "optional": true } ], "desc": "

Create a new Console by passing one or two writable stream instances.\nstdout is a writable stream to print log or info output. stderr\nis used for warning or error output. If stderr isn't passed, the warning\nand error output will be sent to the stdout.\n\n

\n
var output = fs.createWriteStream('./stdout.log');\nvar errorOutput = fs.createWriteStream('./stderr.log');\n// custom simple logger\nvar logger = new Console(output, errorOutput);\n// use it like console\nvar count = 5;\nlogger.log('count: %d', count);\n// in stdout.log: count 5
\n

The global console is a special Console whose output is sent to\nprocess.stdout and process.stderr:\n\n

\n
new Console(process.stdout, process.stderr);
\n" } ] } ], "type": "module", "displayName": "Console" } ] }