#33920 closed Cleanup/optimization (fixed)
Document that LOGGING_CONFIG callback is not called when LOGGING dict is not set.
| Reported by: | Craig de Stigter | Owned by: | Kinza-Raza |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Claude Paroz, Daniele Procida | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
the docs say:
LOGGING_CONFIG¶ Default: 'logging.config.dictConfig' A path to a callable that will be used to configure logging in the Django project. Points at an instance of Python’s dictConfig configuration method by default. If you set LOGGING_CONFIG to None, the logging configuration process will be skipped.
https://docs.djangoproject.com/en/4.1/ref/settings/#logging-config
It turns out that in fact, you need to set LOGGING to some non-falsey value for the LOGGING_CONFIG callback to even be called at all. This isn't obvious - part of the reason for having a callback is if your logging is more dynamic than a dict-based config allows.
So now all our apps need some variation of this to work around this bug:
LOGGING = {"note": "this MUST be a non-falsey value for logging to work"}
I think this dependency on LOGGING should be clearly stated in the documentation for LOGGING_CONFIG, or just fixed (by always calling the LOGGING_CONFIG function even if LOGGING is falsey)
Change History (8)
comment:1 by , 3 years ago
| Cc: | added |
|---|---|
| Component: | Uncategorized → Core (Other) |
| Summary: | LOGGING_CONFIG is ignored if LOGGING is falsey or not set → LOGGING_CONFIG callback should be called when LOGGING dict is not set. |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Bug → Cleanup/optimization |
follow-up: 3 comment:2 by , 3 years ago
| Summary: | LOGGING_CONFIG callback should be called when LOGGING dict is not set. → Document that LOGGING_CONFIG callback is not called when LOGGING dict is not set. |
|---|
Unfortunately, the default dictConfig crashes with empty LOGGING:
File "/usr/lib/python3.8/logging/config.py", line 496, in configure
raise ValueError("dictionary doesn't specify a version")
ValueError: dictionary doesn't specify a version
I imagine it might be reasonable to call a custom callback without any configuration.
It's rather niche, and proposed change is backward incompatible, so documenting this restriction seems like a reasonable consensus.
comment:4 by , 3 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:6 by , 3 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Thanks for this report. I imagine it might be reasonable to call a custom callback without any configuration.
This limitation was added in a014ddfef2f606471f25c756d97b3b50fcbd9e91. Claude, does it work for you?