loggers-factory
Version:
Javascript package that makes the use of loggers a breath.
22 lines (20 loc) • 582 B
JavaScript
const { format } = require("winston");
module.exports = function(source) {
return format.combine(
format.colorize(),
format.timestamp(),
format.label({ label: source }),
format.splat(),
format.printf(info => {
if (typeof info.message === "string" || info.message instanceof String) {
return `${info.timestamp} [${info.label.toUpperCase()}.${
process.pid
}] ${info.level}: ${info.message}`;
} else {
return `${info.timestamp} [${info.label.toUpperCase()}.${
process.pid
}] ${info.level}: ${JSON.stringify(info.message)}`;
}
})
);
};