_format = function (msg, style) {
if (!stream) return
var output = ''
if (this.useColor()) {
style = style || {}
var settings = []
if (style.fg) settings.push(style.fg)
if (style.bg) settings.push('bg' + style.bg[0].toUpperCase() + style.bg.slice(1))
if (style.bold) settings.push('bold')
if (style.underline) settings.push('underline')
if (style.inverse) settings.push('inverse')
if (settings.length) output += consoleControl.color(settings)
if (style.beep) output += consoleControl.beep()
}
output += msg
if (this.useColor()) {
output += consoleControl.color('reset')
}
return output
}...
if (!this.progressEnabled) return
var values = {}
if (name) values.section = name
var last = log.record[log.record.length - 1]
if (last) {
values.subsection = last.prefix
var disp = log.disp[last.level] || last.level
var logline = this._format(disp, log.style[last.level])
if (last.prefix) logline += ' ' + this._format(last.prefix, this.prefixStyle)
logline += ' ' + last.message.split(/\r?\n/)[0]
values.logline = logline
}
values.completed = completed || this.tracker.completed()
this.gauge.show(values)
}.bind(log) // bind for use in tracker's on-change listener
...addLevel = function (lvl, n, style, disp) {
// If 'disp' is null or undefined, use the lvl as a default
if (disp == null) disp = lvl
this.levels[lvl] = n
this.style[lvl] = style
if (!this[lvl]) {
this[lvl] = function () {
var a = new Array(arguments.length + 1)
a[0] = lvl
for (var i = 0; i < arguments.length; i++) {
a[i + 1] = arguments[i]
}
return this.log.apply(this, a)
}.bind(this)
}
this.disp[lvl] = disp
}...
log.prefixStyle = { fg: 'magenta' }
log.headingStyle = { fg: 'white', bg: 'black' }
log.style = {}
log.levels = {}
log.disp = {}
log.addLevel('silly', -Infinity, { inverse: true }, 'sill')
log.addLevel('verbose', 1000, { fg: 'blue', bg: 'black' }, 'verb')
log.addLevel('info', 2000, { fg: 'green' })
log.addLevel('http', 3000, { fg: 'green', bg: 'black' })
log.addLevel('warn', 4000, { fg: 'black', bg: 'yellow' }, 'WARN')
log.addLevel('error', 5000, { fg: 'red', bg: 'black' }, 'ERR!')
log.addLevel('silent', Infinity)
...clearProgress = function (cb) {
if (!this.progressEnabled) return cb && process.nextTick(cb)
this.gauge.hide(cb)
}...
if (l === undefined) return
if (l < this.levels[this.level]) return
if (l > 0 && !isFinite(l)) return
// If 'disp' is null or undefined, use the lvl as a default
// Allows: '', 0 as valid disp
var disp = log.disp[m.level] != null ? log.disp[m.level] : m.level
this.clearProgress()
m.message.split(/\r?\n/).forEach(function (line) {
if (this.heading) {
this.write(this.heading, this.headingStyle)
this.write(' ')
}
this.write(disp, log.style[m.level])
var p = m.prefix || ''
...disableColor = function () {
colorEnabled = false
this.gauge.setTheme({hasColor: colorEnabled, hasUnicode: unicodeEnabled})
}...
The stream where output is written.
## log.enableColor()
Force colors to be used on all messages, regardless of the output
stream.
## log.disableColor()
Disable colors on all messages.
## log.enableProgress()
Enable the display of log activity spinner and progress bar
...disableProgress = function () {
if (!this.progressEnabled) return
this.progressEnabled = false
this.tracker.removeListener('change', this.showProgress)
this.gauge.disable()
}...
Disable colors on all messages.
## log.enableProgress()
Enable the display of log activity spinner and progress bar
## log.disableProgress()
Disable the display of a progress bar
## log.enableUnicode()
Force the unicode theme to be used for the progress bar.
...disableUnicode = function () {
unicodeEnabled = false
this.gauge.setTheme({hasColor: this.useColor(), hasUnicode: unicodeEnabled})
}...
Disable the display of a progress bar
## log.enableUnicode()
Force the unicode theme to be used for the progress bar.
## log.disableUnicode()
Disable the use of unicode in the progress bar.
## log.setGaugeTemplate(template)
Set a template for outputting the progress bar. See the [gauge documentation] for details.
...emitLog = function (m) {
if (this._paused) {
this._buffer.push(m)
return
}
if (this.progressEnabled) this.gauge.pulse(m.prefix)
var l = this.levels[m.level]
if (l === undefined) return
if (l < this.levels[this.level]) return
if (l > 0 && !isFinite(l)) return
// If 'disp' is null or undefined, use the lvl as a default
// Allows: '', 0 as valid disp
var disp = log.disp[m.level] != null ? log.disp[m.level] : m.level
this.clearProgress()
m.message.split(/\r?\n/).forEach(function (line) {
if (this.heading) {
this.write(this.heading, this.headingStyle)
this.write(' ')
}
this.write(disp, log.style[m.level])
var p = m.prefix || ''
if (p) this.write(' ')
this.write(p, this.prefixStyle)
this.write(' ' + line + '\n')
}, this)
this.showProgress()
}...
log.resume = function () {
if (!this._paused) return
this._paused = false
var b = this._buffer
this._buffer = []
b.forEach(function (m) {
this.emitLog(m)
}, this)
if (this.progressEnabled) this.gauge.enable()
}
log._buffer = []
var id = 0
...enableColor = function () {
colorEnabled = true
this.gauge.setTheme({hasColor: colorEnabled, hasUnicode: unicodeEnabled})
}...
## log.stream
* {Stream} Default: `process.stderr`
The stream where output is written.
## log.enableColor()
Force colors to be used on all messages, regardless of the output
stream.
## log.disableColor()
Disable colors on all messages.
...enableProgress = function () {
if (this.progressEnabled) return
this.progressEnabled = true
this.tracker.on('change', this.showProgress)
if (this._pause) return
this.gauge.enable()
}...
Force colors to be used on all messages, regardless of the output
stream.
## log.disableColor()
Disable colors on all messages.
## log.enableProgress()
Enable the display of log activity spinner and progress bar
## log.disableProgress()
Disable the display of a progress bar
...enableUnicode = function () {
unicodeEnabled = true
this.gauge.setTheme({hasColor: this.useColor(), hasUnicode: unicodeEnabled})
}...
Enable the display of log activity spinner and progress bar
## log.disableProgress()
Disable the display of a progress bar
## log.enableUnicode()
Force the unicode theme to be used for the progress bar.
## log.disableUnicode()
Disable the use of unicode in the progress bar.
...error = function () { [native code] }...
For example,
* log.silly(prefix, message, ...)
* log.verbose(prefix, message, ...)
* log.info(prefix, message, ...)
* log.http(prefix, message, ...)
* log.warn(prefix, message, ...)
* log.error(prefix, message, ...)
Like `log.log(level, prefix, message, ...)`. In this way, each level is
given a shorthand, so you can do `log.info(prefix, message)`.
## log.addLevel(level, n, style, disp)
* `level` {String} Level indicator
...gauge._themes = function (opts) {
return themeset.getDefault(opts)
}n/a
http = function () { [native code] }...
## log\[level](prefix, message, ...)
For example,
* log.silly(prefix, message, ...)
* log.verbose(prefix, message, ...)
* log.info(prefix, message, ...)
* log.http(prefix, message, ...)
* log.warn(prefix, message, ...)
* log.error(prefix, message, ...)
Like `log.log(level, prefix, message, ...)`. In this way, each level is
given a shorthand, so you can do `log.info(prefix, message)`.
## log.addLevel(level, n, style, disp)
...info = function () { [native code] }...
var log = require('npmlog')
// additional stuff ---------------------------+
// message ----------+ |
// prefix ----+ | |
// level -+ | | |
// v v v v
log.info('fyi', 'I have a kitty cat: %j', myKittyCat)
```
## log.level
* {String}
The level to display logs at. Any logs at or above this level will be
...log = function () { [native code] }...
Stop emitting messages to the stream, but do not drop them.
## log.resume()
Emit all buffered messages that were written while paused.
## log.log(level, prefix, message, ...)
* `level` {String} The level to emit the message at
* `prefix` {String} A string prefix. Set to "" to skip.
* `message...` Arguments to `util.format`
Emit a log message at the specified level.
...newGroup = function () { return mixinLog(this.tracker[C].apply(this.tracker, arguments)) }...
## log.newStream(name, todo, weight)
This adds a new `are-we-there-yet` stream tracker to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
`are-we-there-yet` `TrackerStream` object.
## log.newGroup(name, weight)
This adds a new `are-we-there-yet` tracker group to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
`are-we-there-yet` `TrackerGroup` object.
# Events
...newItem = function () { return mixinLog(this.tracker[C].apply(this.tracker, arguments)) }...
Sets up a new level with a shorthand function and so forth.
Note that if the number is `Infinity`, then setting the level to that
will cause all log messages to be suppressed. If the number is
`-Infinity`, then the only way to show it is to enable all log messages.
## log.newItem(name, todo, weight)
* `name` {String} Optional; progress item name.
* `todo` {Number} Optional; total amount of work to be done. Default 0.
* `weight` {Number} Optional; the weight of this item relative to others. Default 1.
This adds a new `are-we-there-yet` item tracker to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
...newStream = function () { return mixinLog(this.tracker[C].apply(this.tracker, arguments)) }...
* `todo` {Number} Optional; total amount of work to be done. Default 0.
* `weight` {Number} Optional; the weight of this item relative to others. Default 1.
This adds a new `are-we-there-yet` item tracker to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
`are-we-there-yet` `Tracker` object.
## log.newStream(name, todo, weight)
This adds a new `are-we-there-yet` stream tracker to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
`are-we-there-yet` `TrackerStream` object.
## log.newGroup(name, weight)
...pause = function () {
this._paused = true
if (this.progressEnabled) this.gauge.disable()
}...
[gauge documentation]: https://npmjs.com/package/gauge
## log.setGaugeThemeset(themes)
Select a themeset to pick themes from for the progress bar. See the [gauge documentation] for details.
## log.pause()
Stop emitting messages to the stream, but do not drop them.
## log.resume()
Emit all buffered messages that were written while paused.
...resume = function () {
if (!this._paused) return
this._paused = false
var b = this._buffer
this._buffer = []
b.forEach(function (m) {
this.emitLog(m)
}, this)
if (this.progressEnabled) this.gauge.enable()
}...
Select a themeset to pick themes from for the progress bar. See the [gauge documentation] for details.
## log.pause()
Stop emitting messages to the stream, but do not drop them.
## log.resume()
Emit all buffered messages that were written while paused.
## log.log(level, prefix, message, ...)
* `level` {String} The level to emit the message at
* `prefix` {String} A string prefix. Set to "" to skip.
...setGaugeTemplate = function (template) {
this.gauge.setTemplate(template)
}...
Force the unicode theme to be used for the progress bar.
## log.disableUnicode()
Disable the use of unicode in the progress bar.
## log.setGaugeTemplate(template)
Set a template for outputting the progress bar. See the [gauge documentation] for details.
[gauge documentation]: https://npmjs.com/package/gauge
## log.setGaugeThemeset(themes)
...setGaugeThemeset = function (themes) {
this.gauge.setThemeset(themes)
}...
## log.setGaugeTemplate(template)
Set a template for outputting the progress bar. See the [gauge documentation] for details.
[gauge documentation]: https://npmjs.com/package/gauge
## log.setGaugeThemeset(themes)
Select a themeset to pick themes from for the progress bar. See the [gauge documentation] for details.
## log.pause()
Stop emitting messages to the stream, but do not drop them.
...showProgress = function () { [native code] }...
}
this.write(disp, log.style[m.level])
var p = m.prefix || ''
if (p) this.write(' ')
this.write(p, this.prefixStyle)
this.write(' ' + line + '\n')
}, this)
this.showProgress()
}
log._format = function (msg, style) {
if (!stream) return
var output = ''
if (this.useColor()) {
...silent = function () { [native code] }n/a
silly = function () { [native code] }...
Emit a log message at the specified level.
## log\[level](prefix, message, ...)
For example,
* log.silly(prefix, message, ...)
* log.verbose(prefix, message, ...)
* log.info(prefix, message, ...)
* log.http(prefix, message, ...)
* log.warn(prefix, message, ...)
* log.error(prefix, message, ...)
Like `log.log(level, prefix, message, ...)`. In this way, each level is
...useColor = function () {
return colorEnabled != null ? colorEnabled : stream.isTTY
}...
}
// default level
log.level = 'info'
log.gauge = new Gauge(stream, {
enabled: false, // no progress bars unless asked
theme: {hasColor: log.useColor()},
template: [
{type: 'progressbar', length: 20},
{type: 'activityIndicator', kerning: 1, length: 1},
{type: 'section', default: ''},
':',
{type: 'logline', kerning: 1, default: ''}
]
...verbose = function () { [native code] }...
Emit a log message at the specified level.
## log\[level](prefix, message, ...)
For example,
* log.silly(prefix, message, ...)
* log.verbose(prefix, message, ...)
* log.info(prefix, message, ...)
* log.http(prefix, message, ...)
* log.warn(prefix, message, ...)
* log.error(prefix, message, ...)
Like `log.log(level, prefix, message, ...)`. In this way, each level is
given a shorthand, so you can do `log.info(prefix, message)`.
...warn = function () { [native code] }...
For example,
* log.silly(prefix, message, ...)
* log.verbose(prefix, message, ...)
* log.info(prefix, message, ...)
* log.http(prefix, message, ...)
* log.warn(prefix, message, ...)
* log.error(prefix, message, ...)
Like `log.log(level, prefix, message, ...)`. In this way, each level is
given a shorthand, so you can do `log.info(prefix, message)`.
## log.addLevel(level, n, style, disp)
...write = function (msg, style) {
if (!stream) return
stream.write(this._format(msg, style))
}...
// If 'disp' is null or undefined, use the lvl as a default
// Allows: '', 0 as valid disp
var disp = log.disp[m.level] != null ? log.disp[m.level] : m.level
this.clearProgress()
m.message.split(/\r?\n/).forEach(function (line) {
if (this.heading) {
this.write(this.heading, this.headingStyle)
this.write(' ')
}
this.write(disp, log.style[m.level])
var p = m.prefix || ''
if (p) this.write(' ')
this.write(p, this.prefixStyle)
this.write(' ' + line + '\n')
...error = function () {}...
For example,
* log.silly(prefix, message, ...)
* log.verbose(prefix, message, ...)
* log.info(prefix, message, ...)
* log.http(prefix, message, ...)
* log.warn(prefix, message, ...)
* log.error(prefix, message, ...)
Like `log.log(level, prefix, message, ...)`. In this way, each level is
given a shorthand, so you can do `log.info(prefix, message)`.
## log.addLevel(level, n, style, disp)
* `level` {String} Level indicator
..._themes = function (opts) {
return themeset.getDefault(opts)
}n/a
_themes = function (opts) {
return themeset.getDefault(opts)
}n/a
addTheme = function (name, parent, theme) {
this.themes[name] = this.newTheme(parent, theme)
}n/a
addToAllThemes = function (theme) {
var themes = this.themes
Object.keys(themes).forEach(function (name) {
objectAssign(themes[name], theme)
})
objectAssign(this.baseTheme, theme)
}n/a
getDefault = function (opts) {
if (!opts) opts = {}
var platformName = opts.platform || process.platform
var platform = this.defaults[platformName] || this.defaults.fallback
var hasUnicode = !!opts.hasUnicode
var hasColor = !!opts.hasColor
if (!platform) throw this.newMissingDefaultThemeError(platformName, hasUnicode, hasColor)
if (!platform[hasUnicode][hasColor]) {
if (hasUnicode && hasColor && platform[!hasUnicode][hasColor]) {
hasUnicode = false
} else if (hasUnicode && hasColor && platform[hasUnicode][!hasColor]) {
hasColor = false
} else if (hasUnicode && hasColor && platform[!hasUnicode][!hasColor]) {
hasUnicode = false
hasColor = false
} else if (hasUnicode && !hasColor && platform[!hasUnicode][hasColor]) {
hasUnicode = false
} else if (!hasUnicode && hasColor && platform[hasUnicode][!hasColor]) {
hasColor = false
} else if (platform === this.defaults.fallback) {
throw this.newMissingDefaultThemeError(platformName, hasUnicode, hasColor)
}
}
if (platform[hasUnicode][hasColor]) {
return this.getTheme(platform[hasUnicode][hasColor])
} else {
return this.getDefault(objectAssign({}, opts, {platform: 'fallback'}))
}
}n/a
getTheme = function (name) {
if (!this.themes[name]) throw this.newMissingThemeError(name)
return this.themes[name]
}n/a
getThemeNames = function () {
return Object.keys(this.themes)
}n/a
function newMissingDefaultThemeError(platformName, hasUnicode, hasColor) {
var err = new Error(
'Could not find a gauge theme for your platform/unicode/color use combo:\n' +
' platform = ' + platformName + '\n' +
' hasUnicode = ' + hasUnicode + '\n' +
' hasColor = ' + hasColor)
Error.captureStackTrace.call(err, newMissingDefaultThemeError)
err.platform = platformName
err.hasUnicode = hasUnicode
err.hasColor = hasColor
err.code = 'EMISSINGTHEME'
return err
}n/a
function newMissingThemeError(name) {
var err = new Error('Could not find a gauge theme named "' + name + '"')
Error.captureStackTrace.call(err, newMissingThemeError)
err.theme = name
err.code = 'EMISSINGTHEME'
return err
}n/a
newTheme = function (parent, theme) {
if (!theme) {
theme = parent
parent = this.baseTheme
}
return objectAssign({}, parent, theme)
}n/a
newThemeSet = function () {
var themeset = function (opts) {
return themeset.getDefault(opts)
}
return objectAssign(themeset, ThemeSetProto, {
themes: objectAssign({}, this.themes),
baseTheme: objectAssign({}, this.baseTheme),
defaults: JSON.parse(JSON.stringify(this.defaults || {}))
})
}n/a
setDefault = function (opts, name) {
if (name == null) {
name = opts
opts = {}
}
var platform = opts.platform == null ? 'fallback' : opts.platform
var hasUnicode = !!opts.hasUnicode
var hasColor = !!opts.hasColor
if (!this.defaults[platform]) this.defaults[platform] = {true: {}, false: {}}
this.defaults[platform][hasUnicode][hasColor] = name
}n/a
_write = function (chunk, encoding, callback) {
process.stdout._writeDefault(chunk, encoding, callback);
// coverage-hack
self.nop(self.socket.readable && (function () {
self.socket.write(chunk, encoding);
}()));
}n/a
_writeDefault = function (data, encoding, cb) {
this._writeGeneric(false, data, encoding, cb);
}n/a
destroy = function (er) {
er = er || new Error('process.stdout cannot be closed.');
stdout.emit('error', er);
}n/a
destroySoon = function (er) {
er = er || new Error('process.stdout cannot be closed.');
stdout.emit('error', er);
}n/a
destroy = function (er) {
er = er || new Error('process.stderr cannot be closed.');
stderr.emit('error', er);
}n/a
destroySoon = function (er) {
er = er || new Error('process.stderr cannot be closed.');
stderr.emit('error', er);
}n/a
bubbleChange = function (name, completed, tracker) {
trackerGroup.completion[tracker.id] = completed
if (trackerGroup.finished) return
trackerGroup.emit('change', name || trackerGroup.name, trackerGroup.completed(), trackerGroup)
}n/a