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 var log = require('npmlog')
18 // additional stuff ---------------------------+
19 // message ----------+ |
23 log.info('fyi', 'I have a kitty cat: %j', myKittyCat)
30 The level to display logs at. Any logs at or above this level will be
31 displayed. The special level `silent` will prevent anything from being
38 An array of all the log messages that have been entered.
44 The maximum number of records to keep. If log.record gets bigger than
45 10% over this value, then it is sliced down to 90% of this value.
47 The reason for the 10% window is so that it doesn't have to resize a
48 large array on every log entry.
54 A style object that specifies how prefixes are styled. (See below)
60 A style object that specifies how the heading is styled. (See below)
64 * {String} Default: ""
66 If set, a heading that is printed at the start of every line.
70 * {Stream} Default: `process.stderr`
72 The stream where output is written.
76 Force colors to be used on all messages, regardless of the output
81 Disable colors on all messages.
83 ## log.enableProgress()
85 Enable the display of log activity spinner and progress bar
87 ## log.disableProgress()
89 Disable the display of a progress bar
91 ## log.enableUnicode()
93 Force the unicode theme to be used for the progress bar.
95 ## log.disableUnicode()
97 Disable the use of unicode in the progress bar.
99 ## log.setGaugeTemplate(template)
101 Overrides the default gauge template.
105 Stop emitting messages to the stream, but do not drop them.
109 Emit all buffered messages that were written while paused.
111 ## log.log(level, prefix, message, ...)
113 * `level` {String} The level to emit the message at
114 * `prefix` {String} A string prefix. Set to "" to skip.
115 * `message...` Arguments to `util.format`
117 Emit a log message at the specified level.
119 ## log\[level](prefix, message, ...)
123 * log.silly(prefix, message, ...)
124 * log.verbose(prefix, message, ...)
125 * log.info(prefix, message, ...)
126 * log.http(prefix, message, ...)
127 * log.warn(prefix, message, ...)
128 * log.error(prefix, message, ...)
130 Like `log.log(level, prefix, message, ...)`. In this way, each level is
131 given a shorthand, so you can do `log.info(prefix, message)`.
133 ## log.addLevel(level, n, style, disp)
135 * `level` {String} Level indicator
136 * `n` {Number} The numeric level
137 * `style` {Object} Object with fg, bg, inverse, etc.
138 * `disp` {String} Optional replacement for `level` in the output.
140 Sets up a new level with a shorthand function and so forth.
142 Note that if the number is `Infinity`, then setting the level to that
143 will cause all log messages to be suppressed. If the number is
144 `-Infinity`, then the only way to show it is to enable all log messages.
146 ## log.newItem(name, todo, weight)
148 * `name` {String} Optional; progress item name.
149 * `todo` {Number} Optional; total amount of work to be done. Default 0.
150 * `weight` {Number} Optional; the weight of this item relative to others. Default 1.
152 This adds a new `are-we-there-yet` item tracker to the progress tracker. The
153 object returned has the `log[level]` methods but is otherwise an
154 `are-we-there-yet` `Tracker` object.
156 ## log.newStream(name, todo, weight)
158 This adds a new `are-we-there-yet` stream tracker to the progress tracker. The
159 object returned has the `log[level]` methods but is otherwise an
160 `are-we-there-yet` `TrackerStream` object.
162 ## log.newGroup(name, weight)
164 This adds a new `are-we-there-yet` tracker group to the progress tracker. The
165 object returned has the `log[level]` methods but is otherwise an
166 `are-we-there-yet` `TrackerGroup` object.
170 Events are all emitted with the message object.
172 * `log` Emitted for all messages
173 * `log.<level>` Emitted for all messages with the `<level>` level.
174 * `<prefix>` Messages with prefixes also emit their prefix as an event.
178 Style objects can have the following fields:
180 * `fg` {String} Color for the foreground text
181 * `bg` {String} Color for the background
182 * `bold`, `inverse`, `underline` {Boolean} Set the associated property
183 * `bell` {Boolean} Make a noise (This is pretty annoying, probably.)
187 Every log event is emitted with a message object, and the `log.record`
188 list contains all of them that have been created. They have the
194 * `message` {String} Result of `util.format()`
195 * `messageRaw` {Array} Arguments to `util.format()`