boop
boop

Reputation: 7787

WinstonJS custom levels

So I wanted to add two levels to my logger. But it is not logging, I have no idea why.. Here is my setup. Any ideas?

// setup
var logLevels = {
    levels: {
        trace: 0,
        debug: 1,
        info: 2,
        warn: 3,
        error: 4,
        critical: 5
    }
};

var logger = new (winston.Logger)({
    levels: logLevels.levels,
    transports: [
        new winston.transports.Console()
    ]
});

// test
console.info('----------------------');
logger.trace('trace');
logger.debug('debug');
logger.info('info');
logger.warn('warn');
logger.error('error');
logger.critical('critical');
console.info('----------------------');

Output:

----------------------
debug: debug
trace: trace
info: info
----------------------

Upvotes: 6

Views: 6103

Answers (1)

Alexey B.
Alexey B.

Reputation: 12033

winston Logging levels

First problem here, Each level is given a specific integer priority. By default, its

{ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }

So less is more important.

Second, you must specify level to each transport. In your case, you must set level to critical to show all messages.

winston allows you to define a level property on each transport which specifies the maximum level of messages that a transport should log.

var logger = new (winston.Logger)({
    levels: logLevels.levels,
    transports: [
        new winston.transports.Console({level: 'critical'})
    ]
});

Upvotes: 12

Related Questions