Opened 22 months ago

Closed 21 months ago

Last modified 21 months ago

#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 Mariusz Felisiak, 22 months ago

Cc: Claude Paroz Daniele Procida added
Component: UncategorizedCore (Other)
Summary: LOGGING_CONFIG is ignored if LOGGING is falsey or not setLOGGING_CONFIG callback should be called when LOGGING dict is not set.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

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?

comment:2 by Mariusz Felisiak, 22 months 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.

in reply to:  2 comment:3 by Kinza-Raza, 22 months ago

I'd like to take this up.

comment:4 by Kinza-Raza, 22 months ago

Owner: changed from nobody to Kinza-Raza
Status: newassigned

comment:6 by Carlton Gibson, 21 months ago

Triage Stage: AcceptedReady for checkin

comment:7 by Carlton Gibson <carlton@…>, 21 months ago

Resolution: fixed
Status: assignedclosed

In 5f5401b1:

Fixed #33920 -- Doc'd dependency of LOGGING_CONFIG callback on non-empty LOGGING.

comment:8 by Carlton Gibson <carlton.gibson@…>, 21 months ago

In dafdceda:

[4.1.x] Fixed #33920 -- Doc'd dependency of LOGGING_CONFIG callback on non-empty LOGGING.

Backport of 5f5401b1149dca4a487eec6b1008124eacc7d29f from main

Note: See TracTickets for help on using tickets.
Back to Top