You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.0 KiB
JavaScript

'use strict';
var chalk = require("chalk");
var spy = require("through2-spy");
var fancyLog = require("fancy-log");
var padWidth = 5;
var typeColors = {
error: "red",
warn: "yellow",
info: "cyan",
debug: "gray"
};
module.exports = function namedLog(name) {
var prefix = "[" + chalk.green(name) + "]";
function createLog(type) {
var prefixes = [prefix];
if (type) {
var typeColor = typeColors[type] != null ? typeColors[type] : "white";
var typePrefix = "[" + chalk[typeColor](type) + "]";
prefixes.push(typePrefix);
}
return function log() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
fancyLog.apply(null, prefixes.concat(args));
};
}
return {
debug: createLog("debug"),
info: createLog("info"),
warn: createLog("warn"),
error: createLog("error"),
log: createLog(),
stream: function stream() {
var _this = this;
return spy.obj(function (file) {
_this.info(file.path, file.contents);
});
}
};
};