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 [https://stackoverflow.com/questions/20282521/django-
request-logger-not-propagated-to-root 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 [https://stackoverflow.com/a/53496459/2996101 -as shown in
this answer-] are in accordance with the
[https://docs.python.org/3/library/logging.html#logging.Logger.propagate
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/29991>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
Comment:
Would you like to offer a patch?
--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:1>
* status: new => assigned
* owner: nobody => George Tantiras
--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:2>
* has_patch: 0 => 1
Comment:
Added https://github.com/django/django/pull/10699
--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"793a71b7be9970bee8cbac68985684628e99ad23" 793a71b]:
{{{
#!CommitTicketReference repository=""
revision="793a71b7be9970bee8cbac68985684628e99ad23"
Fixed #29991 -- Doc'd logger propogation for the default logging config.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"8f8be2a8d72643592d697317268e85e7887f2bbf" 8f8be2a8]:
{{{
#!CommitTicketReference repository=""
revision="8f8be2a8d72643592d697317268e85e7887f2bbf"
[2.1.x] Fixed #29991 -- Doc'd logger propogation for the default logging
config.
Backport of 793a71b7be9970bee8cbac68985684628e99ad23 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:6>