[英]Why does INFO get logged in DEBUG logs
I am using yaml to config logging for my Python application. 我正在使用yaml为我的Python应用程序配置日志记录。
version: 1
disable_existing_loggers: False
formatters:
standard:
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: standard
stream: ext://sys.stdout
info_file_handler:
class: logging.handlers.RotatingFileHandler
level: INFO
formatter: standard
filename: info.log
maxBytes: 10485760 # 10MB
backupCount: 20
encoding: utf8
error_file_handler:
class: logging.handlers.RotatingFileHandler
level: ERROR
formatter: standard
filename: errors.log
maxBytes: 10485760 # 10MB
backupCount: 20
encoding: utf8
debug_file_handler:
class: logging.handlers.RotatingFileHandler
level: DEBUG
formatter: standard
filename: debug.log
maxBytes: 10485760 # 10MB
backupCount: 20
encoding: utf8
loggers:
db_ops:
level: DEBUG
handlers: [info_file_handler, error_file_handler, debug_file_handler]
propagate: true
In module db_ops
, I use both logger.info
and logger.debug
for different levels of logging. 在模块
db_ops
,我同时使用logger.info
和logger.debug
针对不同级别的日志记录。 When I run the app, while INFO
did get output to info.log, both INFO
and DEBUG
messages are output to debug.log. 当我运行该应用程序时,虽然
INFO
确实将输出输出到info.log,但是INFO
和DEBUG
消息均输出到debug.log。
What is the right way to separate the log to different files based on the level? 根据级别将日志分隔到不同文件的正确方法是什么?
The levels of python loggers and handlers are thresholds. python记录器和处理程序的级别是阈值。 If you specify your level as DEBUG, it means that anything equal or above DEBUG will be logged.
如果将级别指定为DEBUG,则意味着将记录任何等于或大于DEBUG的值。
If you want to have a DEBUG logging only, you'll have to additionally assign a filter that will filter anything but DEBUG message. 如果只想使用DEBUG日志记录,则必须另外分配一个过滤器,该过滤器将过滤除DEBUG消息以外的任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.