Opened 10 years ago
Last modified 7 months ago
#26688 closed Bug
Inconsistent logging of 5xx and 4xx requests to django.request — at Version 1
| Reported by: | Samir Shah | Owned by: | nobody |
|---|---|---|---|
| Component: | HTTP handling | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | seocam@… | 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 (last modified by )
The documentation for django.request says:
Log messages related to the handling of requests. 5XX responses are raised as ERROR messages; 4XX responses are raised as WARNING messages.
The actual behaviour is not quite consistent with this:
- Only
4xxand500responses are logged todjango.request- not any other responses in the5xxrange.
500responses are only logged if they are the result of an uncaught exception. The logging happens indjango.core.handlers.base.handle_uncaught_exception. If a view manually sets a500response somewhere, this isn't logged.
- The same was true of
404responses (they were only logged if an uncaughtHttp404was raised), until the change made in ticket:26504 inadvertently altered this behaviour. After that change, all404s are logged regardless of how they are generated.
- Other
4xxresponses meanwhile are only logged as the result of an exception (PermissionDeniedetc.), not if the status code is set manually.
400responses are logged todjango.securitybut not todjango.request.
I would be happy to submit a patch that addresses this but would like some guidance on what the best solution is. My initial thoughts are:
- I think Django should log all
5xxresponses, regardless of how they were generated. This would mean refactoring the logic that does this logging.
- Either log all
4xxresponses todjango.requestor change the documentation to list what specific responses are logged.
Note:
See TracTickets
for help on using tickets.