Merge remote-tracking branch 'upstream/v0.10'
[platform/upstream/nodejs.git] / doc / api / console.markdown
1 # console
2
3     Stability: 4 - API Frozen
4
5 * {Object}
6
7 <!--type=global-->
8
9 For printing to stdout and stderr.  Similar to the console object functions
10 provided by most web browsers, here the output is sent to stdout or stderr.
11
12 The console functions are synchronous when the destination is a terminal or
13 a file (to avoid lost messages in case of premature exit) and asynchronous
14 when it's a pipe (to avoid blocking for long periods of time).
15
16 That is, in the following example, stdout is non-blocking while stderr
17 is blocking:
18
19     $ node script.js 2> error.log | tee info.log
20
21 In daily use, the blocking/non-blocking dichotomy is not something you
22 should worry about unless you log huge amounts of data.
23
24
25 ## console.log([data], [...])
26
27 Prints to stdout with newline. This function can take multiple arguments in a
28 `printf()`-like way. Example:
29
30     console.log('count: %d', count);
31
32 If formatting elements are not found in the first string then `util.inspect`
33 is used on each argument.  See [util.format()][] for more information.
34
35 ## console.info([data], [...])
36
37 Same as `console.log`.
38
39 ## console.error([data], [...])
40
41 Same as `console.log` but prints to stderr.
42
43 ## console.warn([data], [...])
44
45 Same as `console.error`.
46
47 ## console.dir(obj)
48
49 Uses `util.inspect` on `obj` and prints resulting string to stdout. This function
50 bypasses any custom `inspect()` function on `obj`.
51
52 ## console.time(label)
53
54 Mark a time.
55
56 ## console.timeEnd(label)
57
58 Finish timer, record output. Example:
59
60     console.time('100-elements');
61     for (var i = 0; i < 100; i++) {
62       ;
63     }
64     console.timeEnd('100-elements');
65
66 ## console.trace(label)
67
68 Print a stack trace to stderr of the current position.
69
70 ## console.assert(expression, [message])
71
72 Same as [assert.ok()][] where if the `expression` evaluates as `false` throw an
73 AssertionError with `message`.
74
75 [assert.ok()]: assert.html#assert_assert_value_message_assert_ok_value_message
76 [util.format()]: util.html#util_util_format_format