#30553 closed Cleanup/optimization (fixed)
Misleading logging documentation about disable_existing_loggers default value.
Reported by: | darthdragon | Owned by: | Swatantra |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | disable_existing_loggers logging |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In the documentation it's stated that:
"If the disable_existing_loggers key in the LOGGING dictConfig is set to True (which is the default) ..."
But we can see in https://github.com/django/django/blob/master/django/utils/log.py (master branch commit 10b44e4 at the time of writting) that it is set to False instead:
... DEFAULT_LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { ...
Moving "(which is the default)" in the paragraph should be enough:
"If the disable_existing_loggers key in the LOGGING dictConfig is set to True then all loggers from the default configuration will be disabled. Disabled loggers are not the same as removed; the logger will still exist, but will silently discard anything logged to it, not even propagating entries to a parent logger. Thus you should be very careful using 'disable_existing_loggers': True; it’s probably not what you want. Instead, you can set disable_existing_loggers to False (which is the default) and redefine some or all of the default loggers; or you can set LOGGING_CONFIG to None and handle logging config yourself."
Change History (11)
comment:1 by , 5 years ago
Easy pickings: | set |
---|---|
Summary: | Misleading logging documentation about disable_existing_loggers default value → Misleading logging documentation about disable_existing_loggers default value. |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
Version: | 2.2 → master |
comment:2 by , 5 years ago
I think what's meant here is the default for dictConfig if disable_existing_loggers
isn't provided.
If absent, this parameter defaults to
True
.
https://docs.python.org/3.7/library/logging.config.html#dictionary-schema-details
I guess the point is that it's important to provide disable_existing_loggers: False
because often the default behaviour is not what you want. (Why aren't my loggers working? comes up a lot because of this.)
For me, it'd be worth a rephrase to clarify this. (We see a lot of confusions.)
comment:3 by , 5 years ago
Yeah, it seems this kind of thought was exactly what led to #20981 in the first place.
comment:5 by , 5 years ago
I think these two sentences are what may start the headache:
"By default, the LOGGING setting is merged with Django’s default logging configuration using the following scheme.
If the disable_existing_loggers key in the LOGGING dictConfig is set to True (which is the default) then all loggers from the default configuration will be disabled. ...
Because even after reading it 10 times, if you have never looked to python logging.config (and I didn't until today, shame on me), you may not understand that also any loggers that may have been defined before are also disabled.
And maybe clarifying in "Django’s default logging configuration", that the default django loggers are added with disable_existing_loggers=False.
comment:6 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 5 years ago
Patch needs improvement: | set |
---|
As per comment on PR, I think the solution here should just clarify that the "default" in question if that of dictConfig
, rather than referring to the value used by Django's DEFAULT_LOGGING
during startup.
comment:9 by , 5 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Thanks for the report, it seems that this note is incorrect since its introduction in 095643e69145d6899313c518fdd39919c9a89908 because we changed that in 72c65fea41a6a01f24e134e7627417d94746291a.