Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#29991 closed Cleanup/optimization (fixed)

Document logger propagation for the default logging config

Reported by: George Tantiras Owned by: George Tantiras
Component: Documentation Version: 2.1
Severity: Normal Keywords: Logger
Cc: 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

It is very helpful to make it clear in the docs how the Logger setup is structured.

I managed to get the big picture with the following code which makes it very clear that the default handlers are applied to the parent 'django' logger, while all children (except django.server) propagate to their parent.

That was not the default a few years ago and many sources claim that it is better to build a logger from scratch instead of trying to make ends meet with the obscure django default setup.

An example is this S.O question:

The code that delineated the situation and made me trust django logging system, is the following:

$ ./manage.py shell

>>> import logging
>>> # Grub all Django loggers
>>> loggers = [
        name for name in logging.root.manager.loggerDict 
        if 'django' in name
    ]
>>> for each in loggers:
        logger = logging.getLogger(each)
        print(
            'Logger Name: {0}\nLogger Handlers: {1}\n'
            'Logger Propagates: {2}\n\n'.format(
                each, 
                logger.handlers, 
                logger.propagate
            )
        )

The results -as shown in this answer- are in accordance with the propagate docs

A common scenario is to attach handlers only to the root logger, and to let propagation take care of the rest.

Documenting this, will show that django logging system is neat, great and trustworthy.

Change History (6)

comment:1 Changed 10 months ago by Tim Graham

Summary: Better Understanding of Django Logger Default ConfigurationExplain the default logging configuration a bit more
Triage Stage: UnreviewedAccepted

Would you like to offer a patch?

comment:2 Changed 10 months ago by George Tantiras

Owner: changed from nobody to George Tantiras
Status: newassigned

comment:3 Changed 10 months ago by George Tantiras

Has patch: set

comment:4 Changed 10 months ago by Tim Graham

Summary: Explain the default logging configuration a bit moreDocument logger propagation for the default logging config
Triage Stage: AcceptedReady for checkin

comment:5 Changed 10 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 793a71b:

Fixed #29991 -- Doc'd logger propogation for the default logging config.

comment:6 Changed 10 months ago by Tim Graham <timograham@…>

In 8f8be2a8:

[2.1.x] Fixed #29991 -- Doc'd logger propogation for the default logging config.

Backport of 793a71b7be9970bee8cbac68985684628e99ad23 from master.

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