Change python level fileConfig logger

I have a log configured from a file, and I would like to change the level of my logging without changing the .conf file, but using the built-in code instead;

import logging.config

logging.config.fileConfig('..\\LoggingConfig\\loggingfile.conf')

logging.StreamHandler.setLevel(logging.info)

logging.debug("Debug")
logging.info("Info")

This should print only the line of the "Information" log on the screen. I do not know on what object setLevel () can be called! logging.StreamHandler.setLevel (logging.info) is just a hit in the dark after looking for 30 minutes ...

File loggingfile.conf;

[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
+3
source share
2 answers

You need to call setLevelin your instance Logger.

LOGGER = logging.getLogger('your.module.file.name')
LOGGER.setLevel(_level)
LOGGER.info('foo')

If you use only the main registrar, you can do it as follows

logging.basicConfig(level=_level)
logging.info('foo')

See http://docs.python.org/howto/logging.html

+7
source

logging.config.fileConfig , ...

a) :

logging.getLogger().setLevel(logging.WARNING)

b) disable

logging.disable(logging.INFO)
+5

All Articles