|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var util = require("util");
|
|
|
|
|
var path = require("path");
|
|
|
|
|
var chalk = require("chalk");
|
|
|
|
|
var spy = require("through2-spy");
|
|
|
|
|
var fancyLog = require("fancy-log");
|
|
|
|
|
var repeatString = require("repeat-string");
|
|
|
|
|
|
|
|
|
|
var padWidth = 5;
|
|
|
|
|
|
|
|
|
@ -24,6 +26,60 @@ function hexify(buff) {
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderError(err) {
|
|
|
|
|
var message = void 0,
|
|
|
|
|
stack = void 0;
|
|
|
|
|
|
|
|
|
|
if (err.stack != null) {
|
|
|
|
|
var stackLines = err.stack.split("\n");
|
|
|
|
|
message = stackLines[0];
|
|
|
|
|
stack = stackLines.slice(1);
|
|
|
|
|
} else {
|
|
|
|
|
message = err.message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var properties = Object.keys(err).map(function (key) {
|
|
|
|
|
return {
|
|
|
|
|
key: key,
|
|
|
|
|
value: err[key]
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (stack != null) {
|
|
|
|
|
properties.push({
|
|
|
|
|
key: "stacktrace",
|
|
|
|
|
literal: stack.map(function (line) {
|
|
|
|
|
return line.trim();
|
|
|
|
|
}).join("\n")
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var renderedProperties = properties.map(function (property) {
|
|
|
|
|
var renderedValue = void 0;
|
|
|
|
|
|
|
|
|
|
if (property.literal != null) {
|
|
|
|
|
renderedValue = property.literal;
|
|
|
|
|
} else {
|
|
|
|
|
renderedValue = util.inspect(property.value, { colors: true });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chalk.bold.blue(property.key) + ":\n" + indentMultiline(renderedValue);
|
|
|
|
|
}).join("\n");
|
|
|
|
|
|
|
|
|
|
var details = indentMultiline("" + renderedProperties);
|
|
|
|
|
|
|
|
|
|
return chalk.bold.red(message) + "\n" + details;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function indentMultiline(text) {
|
|
|
|
|
var spaces = arguments.length <= 1 || arguments[1] === undefined ? 4 : arguments[1];
|
|
|
|
|
|
|
|
|
|
var indent = repeatString(" ", spaces);
|
|
|
|
|
return text.split("\n").map(function (line) {
|
|
|
|
|
return indent + line;
|
|
|
|
|
}).join("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = function namedLog(name) {
|
|
|
|
|
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
|
|
|
|
|
|
|
|
@ -44,7 +100,12 @@ module.exports = function namedLog(name) {
|
|
|
|
|
args[_key] = arguments[_key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fancyLog.apply(null, prefixes.concat(args));
|
|
|
|
|
if (args[0] instanceof Error) {
|
|
|
|
|
var renderedError = renderError(args[0]);
|
|
|
|
|
fancyLog.apply(null, prefixes.concat([renderedError]));
|
|
|
|
|
} else {
|
|
|
|
|
fancyLog.apply(null, prefixes.concat(args));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|