Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  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};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement