I have a logger configured from a file and would like to change the level of my logging without having to change the .conf file, but instead using inline code;
import logging.config
logging.config.fileConfig('..\\LoggingConfig\\loggingfile.conf')
logging.StreamHandler.setLevel(logging.info)
logging.debug("Debug")
logging.info("Info")
This should only print the "Info" log line to the screen. I don't know on which object to call the setLevel()! logging.StreamHandler.setLevel(logging.info) is just a stab in the dark after 30 mins searching...
The loggingfile.conf file;
[loggers]
keys=root
[logger_root]
handlers=screen
level=NOTSET
[formatter_modfunc]
format=%(module)-20s %(funcName)-25s %(levelno)-3s: %(message)s
[handlers]
keys=screen
[handler_screen]
class=StreamHandler
formatter=modfunc
level=DEBUG
args=(sys.stdout,)
qualname=screen
You need to call setLevel
on your Logger
instance.
LOGGER = logging.getLogger('your.module.file.name')
LOGGER.setLevel(_level)
LOGGER.info('foo')
If you are only using the basic logger, you can do it like this
logging.basicConfig(level=_level)
logging.info('foo')
See http://docs.python.org/howto/logging.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With