SHARE
TWEET

Untitled

a guest Jun 19th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const winston = require(`winston`);
  2.  
  3. function createLogger(opts = {}) {
  4.     const {
  5.         level = `info`,
  6.         getCorrelationId,
  7.         noCorrelationIdValue = `nocorrelation`,
  8.     } = opts;
  9.  
  10.     return winston.createLogger({
  11.         format: winston.format.combine(
  12.             winston.format((info) => {
  13.                 info.correlationId = getCorrelationId() || noCorrelationIdValue;
  14.                 return info;
  15.             })(),
  16.             winston.format.timestamp(),
  17.             winston.format.errors({stack: true}),
  18.             winston.format.colorize(),
  19.             winston.format.printf(({timestamp, correlationId, level, message}) => {
  20.                 return `${timestamp} (${correlationId}) - ${level}: ${message}`;
  21.             })
  22.         ),
  23.         level,
  24.         transports: [
  25.             new winston.transports.Console({
  26.                 handleExceptions: true,
  27.             }),
  28.         ],
  29.         exitOnError: false,
  30.     })
  31. }
  32.  
  33. module.exports = {createLogger};
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top