问题
I try to achieve log level change at run time. i have been following https://github.com/yannvr/Winston-dynamic-loglevel/blob/master/test . while calling update function it doesn't change actual transport level setting. e.g i updated to info level but info related log doesn't print in file. it seems doesnt work what it says is there any other way to achieve it.i have come across using setLevel provide by winston but i dont know how to call it from out side to change log level at run time?
回答1:
Easy, suppose that you want to you use the console as transport for your log, you can start as 'debug' level and later change to 'info'.
'use strict';
const winston = require('winston');
const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: 'debug'
}),
]
});
logger.debug('DEBUG');
logger.transports.console.level = 'info';
logger.debug('DEBUG ?'); // IGNORED !
来源:https://stackoverflow.com/questions/36427982/dynamically-change-log-level-in-winston