I'm running django 1.3, python 2.6.  I'm trying to write a custom
formatter for the django.request logger.  I need to log one of the
headers from the HTTP request.  The documentation for django.request
(https://docs.djangoproject.com/en/1.3/topics/logging/) says:

    Messages to this logger have the following extra context:

    status_code: The HTTP response code associated with the request.
    request: The request object that generated the logging message.

It's not entirely clear what "extra context" means, but I'm assuming
the record passed to my format() method will include those
attributes.  It doesn't.  My formatter looks like:

class UniqueRequestIdFormatter(logging.Formatter):
    def format(self, record):
        record.message = record.msg % record.args
        record.asctime = self.formatTime(record)
        format = '%(asctime)s: %(name)s %(levelname)s %(funcName)s %
(message)s'
        pprint.pprint(record.__dict__)
        return format % record.__dict__

When I log something to this, it prints:

{'args': (),
 'asctime': '2011-09-22 14:54:53,755',
 'created': 1316717693.7554641,
 'exc_info': None,
 'exc_text': None,
 'filename': 'views.py',
 'funcName': 'listen_content',
 'levelname': 'DEBUG',
 'levelno': 10,
 'lineno': 253,
 'message': u"slug = 'essential-motown-hits-songza'",
 'module': 'views',
 'msecs': 755.46407699584961,
 'msg': u"slug = 'essential-motown-hits-songza'",
 'name': 'django.request',
 'pathname': '/home/roy/src/default/djsite/djfront/views.py',
 'process': 18113,
 'processName': 'MainProcess',
 'relativeCreated': 16236.304044723511,
 'thread': 48007945393920,
 'threadName': 'Dummy-1'}

How do I get access to the request object?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to