RoCat / winston-journald

MIT License
2 stars 5 forks source link

How can we set winston levels to the ones here? #6

Closed nschoe closed 7 years ago

nschoe commented 7 years ago

I currently add winston-journald like this (as per the documentation):

const winston = require ('winston')
require('winston-journald').Journald

winston.add(winston.transports.Journald)

The problem is that winston.crit('foo') returns Error: Unknown log level: crit.

In the doc for winston, I see we should be able to winston.setLevels(winston.config.Journald.levels) (then give the example with syslog), but when I print the content of winston.config I've got this:

{ allColors: 
   { error: 'red',
     warn: 'yellow',
     help: 'cyan',
     data: 'grey',
     info: 'green',
     debug: 'blue',
     prompt: 'grey',
     verbose: 'cyan',
     input: 'grey',
     silly: 'magenta',
     emerg: 'red',
     alert: 'yellow',
     crit: 'red',
     warning: 'red',
     notice: 'yellow' },
  addColors: [Function],
  colorize: [Function],
  cli: 
   { levels: 
      { error: 0,
        warn: 1,
        help: 2,
        data: 3,
        info: 4,
        debug: 5,
        prompt: 6,
        verbose: 7,
        input: 8,
        silly: 9 },
     colors: 
      { error: 'red',
        warn: 'yellow',
        help: 'cyan',
        data: 'grey',
        info: 'green',
        debug: 'blue',
        prompt: 'grey',
        verbose: 'cyan',
        input: 'grey',
        silly: 'magenta' } },
  npm: 
   { levels: { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 },
     colors: 
      { error: 'red',
        warn: 'yellow',
        info: 'green',
        verbose: 'cyan',
        debug: 'blue',
        silly: 'magenta' } },
  syslog: 
   { levels: 
      { emerg: 0,
        alert: 1,
        crit: 2,
        error: 3,
        warning: 4,
        notice: 5,
        info: 6,
        debug: 7 },
     colors: 
      { emerg: 'red',
        alert: 'yellow',
        crit: 'red',
        error: 'red',
        warning: 'red',
        notice: 'yellow',
        info: 'green',
        debug: 'blue' } } }

And there is no Journald. So how can I add them?

RoCat commented 7 years ago

It seems that the syslog levels are exactly the same than journald ones.

The only exception is error that become err in journald. There is already an automatic levelname mapping from syslog to journald.

I think you just can do : winston.setLevels(winston.config.syslog.levels);

and then use syslog levels in your code (winson.crit, winston.error etc...)