3 The logger util that npm uses.
5 This logger is very basic. It does the logging for npm. It supports
6 custom levels and colored output.
8 By default, logs are written to stderr. If you want to send log messages
9 to outputs other than streams, then you can change the `log.stream`
10 member, or you can just listen to the events that it emits, and do
11 whatever you want with them.
16 npm install npmlog --save
22 var log = require('npmlog')
24 // additional stuff ---------------------------+
25 // message ----------+ |
29 log.info('fyi', 'I have a kitty cat: %j', myKittyCat)
36 The level to display logs at. Any logs at or above this level will be
37 displayed. The special level `silent` will prevent anything from being
44 An array of all the log messages that have been entered.
50 The maximum number of records to keep. If log.record gets bigger than
51 10% over this value, then it is sliced down to 90% of this value.
53 The reason for the 10% window is so that it doesn't have to resize a
54 large array on every log entry.
60 A style object that specifies how prefixes are styled. (See below)
66 A style object that specifies how the heading is styled. (See below)
70 * {String} Default: ""
72 If set, a heading that is printed at the start of every line.
76 * {Stream} Default: `process.stderr`
78 The stream where output is written.
82 Force colors to be used on all messages, regardless of the output
87 Disable colors on all messages.
89 ## log.enableProgress()
91 Enable the display of log activity spinner and progress bar
93 ## log.disableProgress()
95 Disable the display of a progress bar
97 ## log.enableUnicode()
99 Force the unicode theme to be used for the progress bar.
101 ## log.disableUnicode()
103 Disable the use of unicode in the progress bar.
105 ## log.setGaugeTemplate(template)
107 Set a template for outputting the progress bar. See the [gauge documentation] for details.
109 [gauge documentation]: https://npmjs.com/package/gauge
111 ## log.setGaugeThemeset(themes)
113 Select a themeset to pick themes from for the progress bar. See the [gauge documentation] for details.
117 Stop emitting messages to the stream, but do not drop them.
121 Emit all buffered messages that were written while paused.
123 ## log.log(level, prefix, message, ...)
125 * `level` {String} The level to emit the message at
126 * `prefix` {String} A string prefix. Set to "" to skip.
127 * `message...` Arguments to `util.format`
129 Emit a log message at the specified level.
131 ## log\[level](prefix, message, ...)
135 * log.silly(prefix, message, ...)
136 * log.verbose(prefix, message, ...)
137 * log.info(prefix, message, ...)
138 * log.http(prefix, message, ...)
139 * log.warn(prefix, message, ...)
140 * log.error(prefix, message, ...)
142 Like `log.log(level, prefix, message, ...)`. In this way, each level is
143 given a shorthand, so you can do `log.info(prefix, message)`.
145 ## log.addLevel(level, n, style, disp)
147 * `level` {String} Level indicator
148 * `n` {Number} The numeric level
149 * `style` {Object} Object with fg, bg, inverse, etc.
150 * `disp` {String} Optional replacement for `level` in the output.
152 Sets up a new level with a shorthand function and so forth.
154 Note that if the number is `Infinity`, then setting the level to that
155 will cause all log messages to be suppressed. If the number is
156 `-Infinity`, then the only way to show it is to enable all log messages.
158 ## log.newItem(name, todo, weight)
160 * `name` {String} Optional; progress item name.
161 * `todo` {Number} Optional; total amount of work to be done. Default 0.
162 * `weight` {Number} Optional; the weight of this item relative to others. Default 1.
164 This adds a new `are-we-there-yet` item tracker to the progress tracker. The
165 object returned has the `log[level]` methods but is otherwise an
166 `are-we-there-yet` `Tracker` object.
168 ## log.newStream(name, todo, weight)
170 This adds a new `are-we-there-yet` stream tracker to the progress tracker. The
171 object returned has the `log[level]` methods but is otherwise an
172 `are-we-there-yet` `TrackerStream` object.
174 ## log.newGroup(name, weight)
176 This adds a new `are-we-there-yet` tracker group to the progress tracker. The
177 object returned has the `log[level]` methods but is otherwise an
178 `are-we-there-yet` `TrackerGroup` object.
182 Events are all emitted with the message object.
184 * `log` Emitted for all messages
185 * `log.<level>` Emitted for all messages with the `<level>` level.
186 * `<prefix>` Messages with prefixes also emit their prefix as an event.
190 Style objects can have the following fields:
192 * `fg` {String} Color for the foreground text
193 * `bg` {String} Color for the background
194 * `bold`, `inverse`, `underline` {Boolean} Set the associated property
195 * `bell` {Boolean} Make a noise (This is pretty annoying, probably.)
199 Every log event is emitted with a message object, and the `log.record`
200 list contains all of them that have been created. They have the
206 * `message` {String} Result of `util.format()`
207 * `messageRaw` {Array} Arguments to `util.format()`
211 We use [`set-blocking`](https://npmjs.com/package/set-blocking) to set
212 stderr and stdout blocking if they are tty's and have the setBlocking call.
213 This is a work around for an issue in early versions of Node.js 6.x, which
214 made stderr and stdout non-blocking on OSX. (They are always blocking
215 Windows and were never blocking on Linux.) `npmlog` needs them to be blocking
216 so that it can allow output to stdout and stderr to be interlaced.