简体   繁体   English

Python 日志记录无法更改根记录器的日志级别

[英]Python logging can't change log level of root logger

I'm trying to change the log level of the root logger.我正在尝试更改根记录器的日志级别。 It appears to change when queried with getEffectiveLevel() but doesn't actually log anything different than it did before the change.当使用getEffectiveLevel()进行查询时,它似乎发生了变化,但实际上并没有记录任何与更改前不同的内容。

For example:例如:

>>> import logging
>>> root_logger = logging.getLogger()
>>> root_logger.getEffectiveLevel()
30
>>> root_logger.warning('test')
test
>>> root_logger.info('test')
>>> root_logger.setLevel(logging.DEBUG)
>>> root_logger.getEffectiveLevel()
10
>>> root_logger.warning('test')
test
>>> root_logger.info('test')
>>> root_logger.debug('test')

Why is this?为什么是这样? Am I missing something else I need to do?我错过了我需要做的其他事情吗? It puzzles me that I can set the level and see it with getEffectiveLevel but that it doesn't change the behavior at all.令我困惑的是,我可以设置级别并使用getEffectiveLevel查看它,但它根本不会改变行为。

I am using the built in logging module (version 0.5.1.2) on Python 3.7.3.我在 Python 3.7.3 上使用内置的日志记录模块(版本 0.5.1.2)。

You haven't configured any handlers for the logger (or the logging system at all).您还没有为记录器(或记录系统)配置任何处理程序。

This means that, based on the code here , logging defaults to this last-resort logger, which is a stderr logger with the WARNING threshold, and as such, it doesn't handle those debug messages.这意味着,根据此处的代码logging默认为这个最后的记录器,它是一个带有WARNING阈值的标准错误记录器,因此,它不处理那些调试消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM