-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve logs that LoggingPanel would previously overwrite #1603
Preserve logs that LoggingPanel would previously overwrite #1603
Conversation
78143c2
to
945bd92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good.
I was wondering for a moment if it would be possible to use lastResort
for the toolbar but that would probably be more brittle and less obvious.
I'm always worrying a bit about module-level configuration because of the dependency on import ordering. This will be fine though since Django initializes logging long before the toolbar is initialized for the first time in the middleware.
Is it possible to test this in the test suite? Otherwise this looks good, but needs verification. |
Sorry I didn't mention it, but I verified this with a minimal django app by varying its logging configs. Fully covering this within the test suite might be difficult because of the above mentioned concerns of the original code overriding global behavior at import time. I will look into it though, but let me know if repro is enough. |
I agree with the sentiment that adding a unittest which fully covers this may be hard to do. Maybe it's feasible to add a regression test which emits a logging message without any configured loggers and which verifies that the output appears on If that proves hard to do then I think a description is fine. We're all volunteering here :) |
945bd92
to
5fc9a64
Compare
LoggingPanel upon its import, changes the Python interpreter's root logger to log into a handler that collects its records for the LoggingPanel's display. However for users that don't explicitly configure the root logger this looks like the Debug Toolbar suppresses their logs that previously went to standard error. With this commit, the logs will still keep going to standard error even if the LoggingPanel is installed, but only if the root logger has not been explicitly configured with a handler yet. This behavior will make it so that installing DDT won't break logging neither for users that already have logging customizations nor for users that have an out-of-the-box django default logging setup. Also: change LOGGING config in tests/settings.py because now DDT's own test suite would show more logs without an explicit config.
5fc9a64
to
f470343
Compare
@matthiask I rebased this branch so its first commit is now a regression test. Re: the precommit.ci failure is because of psf/black#2964 |
Thanks! Let's merge this, everything makes a lot of sense to me. |
This might solve the root cause of issues reported in #695 #1078 and #1300
Summary:
LoggingPanel upon its import, changes the Python interpreter's root logger to log into a handler that collects its records for the LoggingPanel's display. However for users that don't explicitly configure the root logger this looks like the Debug Toolbar suppresses their logs that previously went to standard error.
With this commit, the logs will still keep going to standard error even if the LoggingPanel is installed, but only if the root logger has not been explicitly configured with a handler yet.
This behavior will make it so that installing DDT won't break logging neither for users that already have logging customizations nor for users that have an out-of-the-box django default logging setup.
Also: change LOGGING config in tests/settings.py because now DDT's own test suite would show more logs without an explicit config.