Comparing version 3.0.0 to 3.1.0
120
log.js
@@ -5,17 +5,28 @@ 'use strict' | ||
var EE = require('events').EventEmitter | ||
var log = exports = module.exports = new EE | ||
var log = exports = module.exports = new EE() | ||
var util = require('util') | ||
var ansi = require('ansi') | ||
var setBlocking = require('set-blocking') | ||
var consoleControl = require('console-control-strings') | ||
setBlocking(true) | ||
log.cursor = ansi(process.stderr) | ||
log.stream = process.stderr | ||
var stream = process.stderr | ||
Object.defineProperty(log, 'stream', { | ||
set: function (newStream) { | ||
stream = newStream | ||
if (this.gauge) this.gauge.setWriteTo(stream, stream) | ||
}, | ||
get: function () { | ||
return stream | ||
} | ||
}) | ||
// by default, let ansi decide based on tty-ness. | ||
var colorEnabled = undefined | ||
// by default, decide based on tty-ness. | ||
var colorEnabled | ||
log.useColor = function () { | ||
return colorEnabled != null ? colorEnabled : stream.isTTY | ||
} | ||
log.enableColor = function () { | ||
colorEnabled = true | ||
this.cursor.enabled = true | ||
this.gauge.setTheme({hasColor: colorEnabled, hasUnicode: unicodeEnabled}) | ||
@@ -25,3 +36,2 @@ } | ||
colorEnabled = false | ||
this.cursor.enabled = false | ||
this.gauge.setTheme({hasColor: colorEnabled, hasUnicode: unicodeEnabled}) | ||
@@ -33,3 +43,12 @@ } | ||
log.gauge = new Gauge(log.cursor, {tty: log.stream}) | ||
log.gauge = new Gauge(stream, { | ||
theme: {hasColor: log.useColor()}, | ||
template: [ | ||
{type: 'progressbar', length: 20}, | ||
{type: 'activityIndicator', kerning: 1, length: 1}, | ||
{type: 'section'}, | ||
':', | ||
{type: 'logline', kerning: 1} | ||
] | ||
}) | ||
log.tracker = new Progress.TrackerGroup() | ||
@@ -40,7 +59,7 @@ | ||
var unicodeEnabled = undefined | ||
var unicodeEnabled | ||
log.enableUnicode = function () { | ||
unicodeEnabled = true | ||
this.gauge.setTheme({hasColor: colorEnabled, hasUnicode: unicodeEnabled}) | ||
this.gauge.setTheme({hasColor: this.useColor(), hasUnicode: unicodeEnabled}) | ||
} | ||
@@ -50,3 +69,3 @@ | ||
unicodeEnabled = false | ||
this.gauge.setTheme({hasColor: colorEnabled, hasUnicode: unicodeEnabled}) | ||
this.gauge.setTheme({hasColor: this.useColor(), hasUnicode: unicodeEnabled}) | ||
} | ||
@@ -117,4 +136,15 @@ | ||
if (!this.progressEnabled) return | ||
if (completed == null) completed = this.tracker.completed() | ||
this.gauge.show(name, completed) | ||
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 | ||
@@ -153,4 +183,4 @@ | ||
var stack = null | ||
for (var i = 2; i < arguments.length; i ++) { | ||
var arg = a[i-2] = arguments[i] | ||
for (var i = 2; i < arguments.length; i++) { | ||
var arg = a[i - 2] = arguments[i] | ||
@@ -198,3 +228,2 @@ // resolve stack traces to a plain string. | ||
var style = log.style[m.level] | ||
var disp = log.disp[m.level] || m.level | ||
@@ -216,17 +245,28 @@ this.clearProgress() | ||
log.write = function (msg, style) { | ||
if (!this.cursor) return | ||
if (this.stream !== this.cursor.stream) { | ||
this.cursor = ansi(this.stream, { enabled: colorEnabled }) | ||
this.gauge.setWriteTo(this.cursor, this.stream) | ||
log._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 | ||
} | ||
style = style || {} | ||
if (style.fg) this.cursor.fg[style.fg]() | ||
if (style.bg) this.cursor.bg[style.bg]() | ||
if (style.bold) this.cursor.bold() | ||
if (style.underline) this.cursor.underline() | ||
if (style.inverse) this.cursor.inverse() | ||
if (style.beep) this.cursor.beep() | ||
this.cursor.write(msg).reset() | ||
log.write = function (msg, style) { | ||
if (!stream) return | ||
stream.write(this._format(msg, style)) | ||
} | ||
@@ -238,10 +278,12 @@ | ||
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) | ||
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 | ||
@@ -265,2 +307,2 @@ } | ||
// allow 'error' prefix | ||
log.on('error', function(){}) | ||
log.on('error', function () {}) |
@@ -5,3 +5,3 @@ { | ||
"description": "logger for npm", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"repository": { | ||
@@ -16,11 +16,12 @@ "type": "git", | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
"test": "standard && tap test/*.js" | ||
}, | ||
"dependencies": { | ||
"ansi": "~0.3.1", | ||
"are-we-there-yet": "~1.1.2", | ||
"gauge": "~2.5.0", | ||
"console-control-strings": "~1.1.0", | ||
"gauge": "~2.5.2", | ||
"set-blocking": "~2.0.0" | ||
}, | ||
"devDependencies": { | ||
"standard": "~7.1.2", | ||
"tap": "~5.7.0" | ||
@@ -27,0 +28,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16064
5
257
2
- Removedansi@~0.3.1
- Removedansi@0.3.1(transitive)
Updatedgauge@~2.5.2