mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.9 KiB
77 lines
1.9 KiB
13 years ago
|
# console
|
||
|
|
||
13 years ago
|
Stability: 4 - API Frozen
|
||
|
|
||
13 years ago
|
* {Object}
|
||
|
|
||
|
<!--type=global-->
|
||
14 years ago
|
|
||
14 years ago
|
For printing to stdout and stderr. Similar to the console object functions
|
||
|
provided by most web browsers, here the output is sent to stdout or stderr.
|
||
|
|
||
12 years ago
|
The console functions are synchronous when the destination is a terminal or
|
||
|
a file (to avoid lost messages in case of premature exit) and asynchronous
|
||
|
when it's a pipe (to avoid blocking for long periods of time).
|
||
|
|
||
|
That is, in the following example, stdout is non-blocking while stderr
|
||
|
is blocking:
|
||
|
|
||
|
$ node script.js 2> error.log | tee info.log
|
||
|
|
||
|
In daily use, the blocking/non-blocking dichotomy is not something you
|
||
|
should worry about unless you log huge amounts of data.
|
||
|
|
||
|
|
||
13 years ago
|
## console.log([data], [...])
|
||
14 years ago
|
|
||
|
Prints to stdout with newline. This function can take multiple arguments in a
|
||
|
`printf()`-like way. Example:
|
||
|
|
||
|
console.log('count: %d', count);
|
||
|
|
||
13 years ago
|
If formatting elements are not found in the first string then `util.inspect`
|
||
13 years ago
|
is used on each argument. See [util.format()][] for more information.
|
||
14 years ago
|
|
||
13 years ago
|
## console.info([data], [...])
|
||
14 years ago
|
|
||
|
Same as `console.log`.
|
||
|
|
||
13 years ago
|
## console.error([data], [...])
|
||
14 years ago
|
|
||
|
Same as `console.log` but prints to stderr.
|
||
|
|
||
13 years ago
|
## console.warn([data], [...])
|
||
|
|
||
|
Same as `console.error`.
|
||
|
|
||
13 years ago
|
## console.dir(obj)
|
||
14 years ago
|
|
||
12 years ago
|
Uses `util.inspect` on `obj` and prints resulting string to stdout. This function
|
||
|
bypasses any custom `inspect()` function on `obj`.
|
||
14 years ago
|
|
||
13 years ago
|
## console.time(label)
|
||
14 years ago
|
|
||
|
Mark a time.
|
||
|
|
||
13 years ago
|
## console.timeEnd(label)
|
||
14 years ago
|
|
||
13 years ago
|
Finish timer, record output. Example:
|
||
14 years ago
|
|
||
|
console.time('100-elements');
|
||
14 years ago
|
for (var i = 0; i < 100; i++) {
|
||
14 years ago
|
;
|
||
|
}
|
||
|
console.timeEnd('100-elements');
|
||
|
|
||
13 years ago
|
## console.trace(label)
|
||
14 years ago
|
|
||
|
Print a stack trace to stderr of the current position.
|
||
|
|
||
13 years ago
|
## console.assert(expression, [message])
|
||
14 years ago
|
|
||
13 years ago
|
Same as [assert.ok()][] where if the `expression` evaluates as `false` throw an
|
||
|
AssertionError with `message`.
|
||
14 years ago
|
|
||
13 years ago
|
[assert.ok()]: assert.html#assert_assert_value_message_assert_ok_value_message
|
||
|
[util.format()]: util.html#util_util_format_format
|