11

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.

According to the documentation of logging module, there a special root key:

root - this will be the configuration for the root logger. Processing of the configuration will be as for any logger, except that the propagate 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
>>> 
4

1 回答 1

14

无论哪种方式都可以,因为命名的记录器''是根记录器。root如果您正在配置大量记录器,指定顶级键可以更清楚地说明您在做什么 -''记录器配置可能会在一组其他记录器中丢失,而root键与键相邻loggers,因此(理论上)应该更加突出。

重申一下,命名的键root是顶级键;它不在下面loggers

于 2013-11-28T08:51:14.317 回答