Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Colouring custom levels #10

Open
simonl65 opened this issue Jan 30, 2018 · 0 comments
Open

Colouring custom levels #10

simonl65 opened this issue Jan 30, 2018 · 0 comments

Comments

@simonl65
Copy link

simonl65 commented Jan 30, 2018

Hi,

How do I set colours for custom levels? I have the following code:

const winston = require('winston');
const wcf     = require('winston-console-formatter');
const clc     = require('cli-color');

const { formatter, timestamp } = wcf();

const customLevels = {
  levels: {
    sec     : 0,
    audit   : 1,
    error   : 2,
    warn    : 3,
    info    : 4,
    verbose : 5,
    debug   : 6
  },
  colors: {
    sec     : 'magenta',
    audit   : 'cyan',
    error   : 'red',
    warn    : 'yellow',
    info    : 'grey',
    verbose : 'white',
    debug   : 'green'
  }
};

winston.addColors(customLevels.colors);

const customLevelLogger = new (winston.Logger)({ levels: customLevels.levels });

wcf({
  colors: {
    sec     : clc.magenta,
    audit   : clc.yellow,
    error   : clc.red,
    warn    : clc.yellowBright,
    info    : clc.green,
    verbose : clc.gray,
    debug   : clc.cyan
  },
});

customLevelLogger.configure
({
  levels     : customLevels.levels,
  transports : 
  [
    new ( winston.transports.Console )
    ({
      level                           : 'debug',
      formatter,
      timestamp,
      colorize                        : true,
      prettyPrint                     : false,
      handleExceptions                : true,
      humanReadableUnhandledException : true
    })
  ]
});

module.exports = customLevelLogger;

Cheers,
Simon

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant