Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Root logger in dictconfig

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
>>> 
like image 245
warvariuc Avatar asked Nov 28 '13 06:11

warvariuc


Video Answer


1 Answers

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.

To reiterate, the key named root is a top-level key; it's not under loggers.

like image 138
Vinay Sajip Avatar answered Oct 12 '22 01:10

Vinay Sajip