dynamically change log level in winston

余生颓废 提交于 2019-12-11 12:15:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!