Winston: Change default logger transport levels at runtime

Created on 9 Dec 2015  路  1Comment  路  Source: winstonjs/winston

Hello,
From the documentation I see it's possible to reconfigure a transport's level at runtime, but the sample uses a custom logger. Is it possible to do the same with the default logger?
Something like:

var winston=require('winston');
winston.debug("Will not be logged!");
winston.transports.console.level = 'debug'; <--- There is no "console" in transports!
winston.debug("Will be logged in console!");

I've tried to change "console" to "Console" but it does not work...
Thanks!

Most helpful comment

Answering to myself, just in case anybody else asks... I've accessed the default logger through the "Winston.default" property. From there, I can access the transports and do exactly as explained above.
I assume (hope) this is the correct way of proceeding.
This is a sample:

var winston=require('winston');

// Add another transport as an example
winston.add(winston.transports.File, { filename: "somelog.log" });

winston.debug('By default it will not log debugs on console');

// Turn on debugs on default logger console transport
winston.default.transports.console.level='debug';
winston.debug('Now it will log debugs only on console');

// Turn on debugs on default logger file transport
winston.default.transports.file.level='debug';
winston.debug('Now it will log debugs both on console and on file');

>All comments

Answering to myself, just in case anybody else asks... I've accessed the default logger through the "Winston.default" property. From there, I can access the transports and do exactly as explained above.
I assume (hope) this is the correct way of proceeding.
This is a sample:

var winston=require('winston');

// Add another transport as an example
winston.add(winston.transports.File, { filename: "somelog.log" });

winston.debug('By default it will not log debugs on console');

// Turn on debugs on default logger console transport
winston.default.transports.console.level='debug';
winston.debug('Now it will log debugs only on console');

// Turn on debugs on default logger file transport
winston.default.transports.file.level='debug';
winston.debug('Now it will log debugs both on console and on file');
Was this page helpful?
0 / 5 - 0 ratings