Wednesday 7 June 2017

Unable to setup multiple custom logging levels in winston

How to set multiple custom logging levels in winston ??

I want to use 3 logging levels foo, bar, zoo. but, I'm unable to use all the three inside the winston.transports.Console.

I can set only one level by using "level:" inside winston.transports.Console.

'use strict';
const winston = require('winston');

const customLevels = {
  levels: {
    foo: 0,
    bar: 1,
    zoo: 2,
  },
  colors: {
    foo: 'red',
    bar: 'magenta',
    zoo: 'blue'
  }
};

const devLogger = new (winston.Logger)({
  levels: { foo: customLevels.levels.foo, bar: customLevels.levels.bar, zoo: customLevels.levels.zoo },
  transports: [
    new (winston.transports.Console)({
      levels: customLevels.levels,
      colorize: true
    })
  ],
  colors: customLevels.colors
});

devLogger.log('foo', 'hello'); 



via Akshay Barpute

No comments:

Post a Comment