Description
If debug_toolbar
is ever imported (e.g. to add the URL) then it will set up its collection log handler (https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/panels/logging.py#L69)
This happens even if the middleware is not active.
This leads to high memory usage by collecting and retaining all log entries from the root logger.
This is obviously desirable for request handling to display the logs in the toolbar, where the middleware is active, but we encountered this with a django command consuming ever more memory as it ran.
We removed it from INSTALLED_APPS
and MIDDLEWARE
using an ENV var to exclude it, but we had not removed it from urlpatterns
and so debug_toolbar.panels.logging
was still being loaded and was adding its collection logger.
Similarly, if the logger panel is in DISABLE_PANELS
the logger is still added. It is only if the panel is not present in DEBUG_TOOLBAR_PANELS
that it is never loaded and the collection logger is not set up.
We now exclude debug_toolbar from our urlpatterns
too, however it would be good if debug_toolbar only set up this collection logger when it is actually active, rather than always adding it when the module is loaded.
This doesn't appear to be #906, which related explicitly to threading, but has been referenced and worked around by reef-technologies/cookiecutter-rt-django#81 in a similar way to our workaround.