我从一个文件中配置了一个日志记录器,希望更改日志级别而不必更改.conf文件,而是使用内联代码
import logging.config
logging.config.fileConfig('..\\LoggingConfig\\loggingfile.conf')
logging.StreamHandler.setLevel(logging.info)
logging.debug("Debug")
logging.info("Info")
这只会将“信息”日志行打印到屏幕上。我不知道在哪个对象上调用setLevel()!logging.StreamHandler.setLevel(logging.info)只是在搜索了30分钟后在黑暗中捅了一刀。。。
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
当使用logging.config.fileConfig并且您希望同时动态更改所有子记录器的级别时,您可以。。。
a)set level对于root logger:
b)disable其他级别
您需要在
Logger
实例上调用setLevel
。如果您只使用基本记录器,可以这样做
见http://docs.python.org/howto/logging.html
相关问题 更多 >
编程相关推荐