Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23569 closed Bug (fixed)

settings.LOGGING_CONFIG assumes dictConfig()

Reported by: Seth Hill Owned by: nobody
Component: Core (Other) Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It seems that if you set the LOGGING_CONFIG settings var to fileConfig(), django breaks.

It seems like the intention here is to create a set of default logging configurations, and then allow the user to override them. That seems like a good idea, except the DEFAULT_LOGGING variable is a dict, which is passed into the user-defined logging_config_func. So it seems like only dictConfig() is allowed.

The trouble spot seems to be in django/utils/log.py:76:

    if logging_config:
        # First find the logging configuration function ...
        logging_config_func = import_string(logging_config)

        logging_config_func(DEFAULT_LOGGING)

        # ... then invoke it with the logging settings
        if logging_settings:
            logging_config_func(logging_settings)

I think this should be something like:

    if logging_config:
        # First find the logging configuration function ...
        logging_config_func = import_string(logging_config)

        dictConfig(DEFAULT_LOGGING)

        # ... then invoke it with the logging settings
        if logging_settings:
            logging_config_func(logging_settings)

In my case, I have defined

LOGGING_CONFIG = 'logging.config.fileConfig'
LOGGING = '/path/to/ini_file'

Which results in an obscure ConfigParser.NoSectionError: No section: 'formatters', as the fileConfig() is trying to use a ConfigParser to read a dictionary.

Change History (5)

comment:1 by Carl Meyer, 10 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

This analysis seems correct to me.

comment:2 by Seth Hill, 10 years ago

I made a pull request for it here: https://github.com/django/django/pull/3288

comment:3 by Tim Graham, 10 years ago

Needs tests: unset

comment:4 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In fe2afcd318493c933ab1191a5a64271869a1227f:

Fixed #23569 -- Allowed using configs besides dictConfig in LOGGING_CONFIG.

comment:5 by Tim Graham <timograham@…>, 10 years ago

In 494cd857c897dc4051193abc10d181fa51de4966:

Fixed #23653 -- Fixed Windows failure of a logging test added in refs #23569.

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