Is there any way to change the output logging level at runtime? I can't figure out how to do this, but it would be a great feature to add if missing.
Essentially what I want is to be able to define my default logging when the program (a server, in my case) starts up. Then while the program is still running, have the ability to turn the output level up or down. For example, if someone reports a defect, turn the logging to debug for a while to see what's going on and try to capture the problem. Then turn it back to warn or info for "normal" logging.
I saw that Issue #78 is similar to what I want; though I don't need a watchdog component.
I tried using the clear() method followed by add() with a slightly modified set of options, but if the log level changes rapidly then the file transport can write logs in the wrong order. Not a huge deal, but it would be nice if the level were more easily changed instead of completely removing and re-adding everything.
I have achieved that through a wrapper and it is available at: https://github.com/yannvr/Winston-dynamic-loglevel
Thanks @yannvr . I took a quick look at your wrapper; it looks good.
We implemented something very similar on our end. It would still be nice to have this as a feature of winston itself though.
This is possible through logger.setLevels, if you run into an issue again let us know.
In case people run into this in the present, this is now logger.transports[transportName].level = newLogLevel
Doc
@joegoldbeck What is the 'transportName'?
I find this works (using a created logger):
const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: 'debug'
}),
]
});
logger.transports.console.level = 'info';
However trying to do the same on the default logger doesn't work:
winston = require('winston');
winston.transports.console.level = 'info';
I figured out how to assign a transport's name at create time, then use this later.
const logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
level: 'debug',
name: 'fileLog1'
}),
]
});
logger.transports.fileLog1.level = 'info';
@wbkdef - I tried your solution to set the log level dynamically. But it is not working for me. Can you please help me
Hi @kuttiraja , If you still need help, share some of what you've done and what happened. I may then be able to help. This may give you ideas: http://wiki.fast.ai/index.php/How_to_ask_for_Help
Most helpful comment
In case people run into this in the present, this is now
logger.transports[transportName].level = newLogLevelDoc