Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const winston = require(`winston`);
- function createLogger(opts = {}) {
- const {
- level = `info`,
- getCorrelationId,
- noCorrelationIdValue = `nocorrelation`,
- } = opts;
- return winston.createLogger({
- format: winston.format.combine(
- winston.format((info) => {
- info.correlationId = getCorrelationId() || noCorrelationIdValue;
- return info;
- })(),
- winston.format.timestamp(),
- winston.format.errors({stack: true}),
- winston.format.colorize(),
- winston.format.printf(({timestamp, correlationId, level, message}) => {
- return `${timestamp} (${correlationId}) - ${level}: ${message}`;
- })
- ),
- level,
- transports: [
- new winston.transports.Console({
- handleExceptions: true,
- }),
- ],
- exitOnError: false,
- })
- }
- module.exports = {createLogger};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement