python - 无法在 python 中设置日志记录级别
问题描述
以下代码和 yaml 配置生成警告消息,但不生成调试消息,从 Eclipse/Pydev 或命令行运行。未注释 print 语句,配置字典看起来不错。我错过了什么?
setupLogging.py:
#!/usr/bin/env python3
import logging.config
import yaml
def setupLogging():
with open('loggingConfig.yaml', 'rt') as file:
config = yaml.safe_load(file.read())
#print(str(config))
logging.config.dictConfig(config)
if __name__ == "__main__":
setupLogging()
logger = logging.getLogger(__name__)
logger.debug("logger debug")
logger.warning("logger warning")
日志配置.yaml:
---
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
root:
handlers: [console]
...
解决方案
推荐阅读
- image - 克服 ionic 3 iframe 和 ionic 3 的 inapp 浏览器中的图像加载问题
- symfony - 教义不获取外键
- ruby-on-rails - Rails 无法从表单向控制器传递/访问参数
- javascript - 将数据附加到 JSON 数组问题
- arrays - Biqquery 仅更新部分页面路径
- excel - 当单元格即将达到零时,停止从单元格中扣除一行中的值
- ios - iOS tableview重新加载错误
- javascript - 如何在将属性传递给另一个页面时重定向到另一个页面?
- google-cloud-platform - Google 负载均衡器中的黑名单国家/地区
- asp.net-core - 在 odata 控制器中执行查询会导致“已经有一个打开的 DataReader 与此命令关联,必须先关闭它。”