Opened 8 years ago

Closed 8 years ago

#25763 closed Bug (wontfix)

Django missing repr friendly formatting of request

Reported by: Ola Owned by: nobody
Component: Core (Other) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I found this feature https://docs.djangoproject.com/en/1.6/topics/logging/#django-request-logger very useful. Since upgrade to 1.8 request object is no longer nicely formatted

formatter:

'%(asctime)s %(levelname)5.5s [%(name)40.40s]'
    ' (proc.%(process)5.5d) %(funcName)s():%(lineno)d'
    ' HTTP %(status_code)d REQUEST %(request)s')
2015-11-16 13:45:55,579 ERROR [                          django.request] (proc.07627) handle_uncaught_exception():256 HTTP 500 REQUEST <WSGIRequest: GET '/app/error_page/'>
Traceback (most recent call last):...

str or repr(request) is missing, GET, POST, COOKIES and META

Change History (4)

comment:1 by Tim Graham, 8 years ago

This is an intentional change in #12098 and documented in the 1.8 release notes.

Any ideas about how we can improve the situation are welcome, but I don't think we're going to revert that patch.

comment:2 by Ola, 8 years ago

Tim is it not what logging formatting is for?

class HttpRequest(object):

    def __repr__(self):
        return build_request_repr(self)

    def __str__(self):
        if self.method is None or not self.get_full_path():
            return force_str('<%s>' % self.__class__.__name__)
        return force_str(
            '<%s: %s %r>' % (self.__class__.__name__, self.method, force_str(self.get_full_path()))
        )

logging formatter

' HTTP %(status_code)d %(request)r'
<WSGIRequest: GET '/webapp/error_page/'>
[16/Nov/2015 16:29:46] "GET /webapp/error_page/ HTTP/1.1" 200 8366

works for me

I will create a patch for that

Version 0, edited 8 years ago by Ola (next)

comment:3 by Tim Graham, 8 years ago

build_request_repr() was removed in #25099. It solved some security headaches like #22990. I think we want to promote ways of request logging that avoid things like raw passwords in logs.

comment:4 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

I think you should be able to write a custom logging handler similar to AdminEmailHandler which uses record.request to format the request data any way you like. This might be something we'd consider for inclusion in Django itself, although since no one has complained until seven months after the release of Django 1.8, I guess it's not a popular use case. Feel free to raise the issue on the DevelopersMailingList if you feel my analysis is off-base. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top