|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const util = require("util");
|
|
|
|
|
const path = require("path");
|
|
|
|
|
const chalk = require("chalk");
|
|
|
|
|
const spy = require("through2-spy");
|
|
|
|
|
const fancyLog = require("fancy-log");
|
|
|
|
|
const repeatString = require("repeat-string");
|
|
|
|
|
|
|
|
|
|
const padWidth = 5;
|
|
|
|
|
|
|
|
|
@ -24,6 +26,53 @@ function hexify(buff) {
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderError(err) {
|
|
|
|
|
let message, stack;
|
|
|
|
|
|
|
|
|
|
if (err.stack != null) {
|
|
|
|
|
let stackLines = err.stack.split("\n");
|
|
|
|
|
message = stackLines[0];
|
|
|
|
|
stack = stackLines.slice(1);
|
|
|
|
|
} else {
|
|
|
|
|
message = err.message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let properties = Object.keys(err).map((key) => {
|
|
|
|
|
return {
|
|
|
|
|
key: key,
|
|
|
|
|
value: err[key]
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (stack != null) {
|
|
|
|
|
properties.push({
|
|
|
|
|
key: "stacktrace",
|
|
|
|
|
literal: stack.map((line) => line.trim()).join("\n")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let renderedProperties = properties.map((property) => {
|
|
|
|
|
let renderedValue;
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
let details = indentMultiline(`${renderedProperties}`);
|
|
|
|
|
|
|
|
|
|
return `${chalk.bold.red(message)}\n${details}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function indentMultiline(text, spaces = 4) {
|
|
|
|
|
let indent = repeatString(" ", spaces);
|
|
|
|
|
return text.split("\n").map((line) => indent + line).join("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = function namedLog(name, options = {}) {
|
|
|
|
|
let prefix = `[${chalk.green(name)}]`;
|
|
|
|
|
|
|
|
|
@ -38,7 +87,12 @@ module.exports = function namedLog(name, options = {}) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return function log(...args) {
|
|
|
|
|
fancyLog.apply(null, prefixes.concat(args));
|
|
|
|
|
if (args[0] instanceof Error) {
|
|
|
|
|
let renderedError = renderError(args[0]);
|
|
|
|
|
fancyLog.apply(null, prefixes.concat([renderedError]));
|
|
|
|
|
} else {
|
|
|
|
|
fancyLog.apply(null, prefixes.concat(args));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -72,4 +126,4 @@ module.exports = function namedLog(name, options = {}) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|