Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python logging - what does a "root" dict key do?

I am integrating Sentry into my Django project for logging errors, and the starter logging config they recommend starts like this:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'root': {
        'level': 'WARNING',
        'handlers': ['sentry'],
    },
    ...
}

now, I am used to listing my loggers and assigning handlers in the "logging" key like this:

'loggers': {
    '': {
        'handlers': ['console', 'mail_admins'],
        'level': 'INFO',
    },
}

This way I capture output from all loggers (the name '' captures all) and control my handlers.

But what does putting the root key in do to the logging hierarchy? I couldn't find the answer in the python docs.

From what I've seen it just disables all my tuned loggers with the single sentry logger. I stop seeing my errors in the console, etc.

However if I ignore the sentry root advice and just add the logger over here

'loggers': {
    '': {
        'handlers': ['console', 'mail_admins', 'sentry'],
        'level': 'INFO',
    },
}

All my three loggers start working together in harmony.

So I don't get the root thing. What does it do?

like image 999
kurtgn Avatar asked Aug 28 '26 16:08

kurtgn


1 Answers

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.

docs

some more info also stackoverflow

like image 195
Druta Ruslan Avatar answered Aug 31 '26 07:08

Druta Ruslan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!