#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 by , 6 years ago
Summary: | Better Understanding of Django Logger Default Configuration → Explain the default logging configuration a bit more |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 6 years ago
Summary: | Explain the default logging configuration a bit more → Document logger propagation for the default logging config |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Would you like to offer a patch?