'use strict'; const chalk = require("chalk"); const spy = require("through2-spy"); const fancyLog = require("fancy-log"); const padWidth = 5; const typeColors = { error: "red", warn: "yellow", info: "cyan", debug: "gray" } module.exports = function namedLog(name) { let prefix = `[${chalk.green(name)}]`; function createLog(type) { let prefixes = [prefix]; if (type) { let typeColor = (typeColors[type] != null) ? typeColors[type] : "white"; let typePrefix = `[${chalk[typeColor](type)}]`; prefixes.push(typePrefix); } return function log(...args) { fancyLog.apply(null, prefixes.concat(args)); } } return { debug: createLog("debug"), info: createLog("info"), warn: createLog("warn"), error: createLog("error"), log: createLog(), stream: function() { return spy.obj((file) => { this.info(file.path, file.contents); }); } } }