dictconfig中的根记录器 [英] Root logger in dictconfig
问题描述
我想为Django项目设置一个Sentry记录器.我将定义一个sentry
处理程序,并将该处理程序放入具有error
级别的根记录器中.
I want to setup a Sentry logger for a Django project. I will define a sentry
handler and will put that handler in the root logger with error
level.
根据 logging
模块,有一个特殊的root
键:
root
-这将是根记录器的配置.除了propagate
设置将不适用之外,配置处理将与所有记录器相同.
root
- this will be the configuration for the root logger. Processing of the configuration will be as for any logger, except that thepropagate
setting will not be applicable.
同时在其他中放置一个名称为''
的记录器,用于包含根记录器的配置
At the same time in other places a logger with name ''
is used to contain configuration for the root logger.
这具有相同的效果吗?最好是什么?
Does this have the same effect? What is preferable?
>>> import logging
>>> logging.getLogger('') is logging.root
True
>>>
推荐答案
无论哪种方法都可以,因为名为''
的记录器是根记录器.指定顶级键root
可以使您在配置很多记录器时更加清楚自己的操作-''
记录器配置可能会丢失在其他一组记录器中,而root
键是相邻的loggers
键,因此(理论上)应该会更加突出.
Either way will work, because the logger named ''
is the root logger. Specifying the top-level key root
makes it clearer what you're doing if you're configuring a lot of loggers - the ''
logger configuration could be lost inside a group of others, whereas the root
key is adjacent to the loggers
key and so (in theory) should stand out more.
重申一下,名为root
的键是顶级键;它不在loggers
下.
To reiterate, the key named root
is a top-level key; it's not under loggers
.
这篇关于dictconfig中的根记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!