@@ -10,6 +10,42 @@ sent to stdout or stderr.
10
10
For ease of use, ` console ` is defined as a global object and can be used
11
11
directly without ` require ` .
12
12
13
+ ## Class: Console
14
+
15
+ <!-- type=class-->
16
+
17
+ Use ` require('console').Console ` or ` console.Console ` to access this class.
18
+
19
+ var Console = require('console').Console;
20
+ var Console = console.Console;
21
+
22
+ You can use ` Console ` class to custom simple logger like ` console ` , but with
23
+ different output streams.
24
+
25
+ ### new Console(stdout[ , stderr] )
26
+
27
+ Create a new ` Console ` by passing one or two writable stream instances.
28
+ ` stdout ` is a writable stream to print log or info output. ` stderr `
29
+ is used for warning or error output. If ` stderr ` isn't passed, the warning
30
+ and error output will be sent to the ` stdout ` .
31
+
32
+ var output = fs.createWriteStream('./stdout.log');
33
+ var errorOutput = fs.createWriteStream('./stderr.log');
34
+ // custom simple logger
35
+ var logger = new Console(output, errorOutput);
36
+ // use it like console
37
+ var count = 5;
38
+ logger.log('count: %d', count);
39
+ // in stdout.log: count 5
40
+
41
+ The global ` console ` is a special ` Console ` whose output is sent to
42
+ ` process.stdout ` and ` process.stderr ` :
43
+
44
+ new Console(process.stdout, process.stderr);
45
+
46
+ [ assert.ok() ] : assert.html#assert_assert_value_message_assert_ok_value_message
47
+ [ util.format() ] : util.html#util_util_format_format
48
+
13
49
## console
14
50
15
51
* {Object}
@@ -31,30 +67,10 @@ is blocking:
31
67
In daily use, the blocking/non-blocking dichotomy is not something you
32
68
should worry about unless you log huge amounts of data.
33
69
70
+ ### console.assert(value[ , message] [ , ... ] )
34
71
35
- ### console.log([ data] [ , ... ] )
36
-
37
- Prints to stdout with newline. This function can take multiple arguments in a
38
- ` printf() ` -like way. Example:
39
-
40
- var count = 5;
41
- console.log('count: %d', count);
42
- // prints 'count: 5'
43
-
44
- If formatting elements are not found in the first string then ` util.inspect `
45
- is used on each argument. See [ util.format()] [ ] for more information.
46
-
47
- ### console.info([ data] [ , ... ] )
48
-
49
- Same as ` console.log ` .
50
-
51
- ### console.error([ data] [ , ... ] )
52
-
53
- Same as ` console.log ` but prints to stderr.
54
-
55
- ### console.warn([ data] [ , ... ] )
56
-
57
- Same as ` console.error ` .
72
+ Similar to [ assert.ok()] [ ] , but the error message is formatted as
73
+ ` util.format(message...) ` .
58
74
59
75
### console.dir(obj[ , options] )
60
76
@@ -72,6 +88,26 @@ object. This is useful for inspecting large complicated objects. Defaults to
72
88
- ` colors ` - if ` true ` , then the output will be styled with ANSI color codes.
73
89
Defaults to ` false ` . Colors are customizable, see below.
74
90
91
+ ### console.error([ data] [ , ... ] )
92
+
93
+ Same as ` console.log ` but prints to stderr.
94
+
95
+ ### console.info([ data] [ , ... ] )
96
+
97
+ Same as ` console.log ` .
98
+
99
+ ### console.log([ data] [ , ... ] )
100
+
101
+ Prints to stdout with newline. This function can take multiple arguments in a
102
+ ` printf() ` -like way. Example:
103
+
104
+ var count = 5;
105
+ console.log('count: %d', count);
106
+ // prints 'count: 5'
107
+
108
+ If formatting elements are not found in the first string then ` util.inspect `
109
+ is used on each argument. See [ util.format()] [ ] for more information.
110
+
75
111
### console.time(label)
76
112
77
113
Used to calculate the duration of a specific operation. To start a timer, call
@@ -100,43 +136,6 @@ Example:
100
136
Print to stderr ` 'Trace :' ` , followed by the formatted message and stack trace
101
137
to the current position.
102
138
103
- ### console.assert(value[ , message] [ , ... ] )
104
-
105
- Similar to [ assert.ok()] [ ] , but the error message is formatted as
106
- ` util.format(message...) ` .
107
-
108
- ## Class: Console
109
-
110
- <!-- type=class-->
111
-
112
- Use ` require('console').Console ` or ` console.Console ` to access this class.
113
-
114
- var Console = require('console').Console;
115
- var Console = console.Console;
116
-
117
- You can use ` Console ` class to custom simple logger like ` console ` , but with
118
- different output streams.
119
-
120
- ### new Console(stdout[ , stderr] )
121
-
122
- Create a new ` Console ` by passing one or two writable stream instances.
123
- ` stdout ` is a writable stream to print log or info output. ` stderr `
124
- is used for warning or error output. If ` stderr ` isn't passed, the warning
125
- and error output will be sent to the ` stdout ` .
126
-
127
- var output = fs.createWriteStream('./stdout.log');
128
- var errorOutput = fs.createWriteStream('./stderr.log');
129
- // custom simple logger
130
- var logger = new Console(output, errorOutput);
131
- // use it like console
132
- var count = 5;
133
- logger.log('count: %d', count);
134
- // in stdout.log: count 5
135
-
136
- The global ` console ` is a special ` Console ` whose output is sent to
137
- ` process.stdout ` and ` process.stderr ` :
138
-
139
- new Console(process.stdout, process.stderr);
139
+ ### console.warn([ data] [ , ... ] )
140
140
141
- [ assert.ok() ] : assert.html#assert_assert_value_message_assert_ok_value_message
142
- [ util.format() ] : util.html#util_util_format_format
141
+ Same as ` console.error ` .
0 commit comments