[Django] #29991: Better Understanding of Django Logger Default Configuration

4 views
Skip to first unread message

Django

unread,
Nov 27, 2018, 1:18:11 PM11/27/18
to django-...@googlegroups.com
#29991: Better Understanding of Django Logger Default Configuration
------------------------------------------------+------------------------
Reporter: George Tantiras | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.1
Severity: Normal | Keywords: Logger
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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 [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.

Django

unread,
Nov 27, 2018, 5:33:35 PM11/27/18
to django-...@googlegroups.com
#29991: Explain the default logging configuration a bit more
--------------------------------------+------------------------------------

Reporter: George Tantiras | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.1
Severity: Normal | Resolution:
Keywords: Logger | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


Comment:

Would you like to offer a patch?

--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:1>

Django

unread,
Nov 27, 2018, 7:04:17 PM11/27/18
to django-...@googlegroups.com
#29991: Explain the default logging configuration a bit more
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: George
Type: | Tantiras
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 2.1

Severity: Normal | Resolution:
Keywords: Logger | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by George Tantiras):

* status: new => assigned
* owner: nobody => George Tantiras


--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:2>

Django

unread,
Nov 27, 2018, 9:19:54 PM11/27/18
to django-...@googlegroups.com
#29991: Explain the default logging configuration a bit more
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: George
Type: | Tantiras
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 2.1

Severity: Normal | Resolution:
Keywords: Logger | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by George Tantiras):

* has_patch: 0 => 1


Comment:

Added https://github.com/django/django/pull/10699

--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:3>

Django

unread,
Nov 29, 2018, 5:06:22 PM11/29/18
to django-...@googlegroups.com
#29991: Document logger propagation for the default logging config

-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: George
Type: | Tantiras
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 2.1
Severity: Normal | Resolution:
Keywords: Logger | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29991#comment:4>

Django

unread,
Nov 29, 2018, 8:33:21 PM11/29/18
to django-...@googlegroups.com
#29991: Document logger propagation for the default logging config
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: George
Type: | Tantiras
Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.1
Severity: Normal | Resolution: fixed

Keywords: Logger | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Nov 29, 2018, 8:33:22 PM11/29/18
to django-...@googlegroups.com
#29991: Document logger propagation for the default logging config
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: George
Type: | Tantiras
Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.1

Severity: Normal | Resolution: fixed
Keywords: Logger | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages