Am on django 1.3., python 2.6
In the django docs here
https://docs.djangoproject.com/en/1.3/topics/logging/#django-request
it says that messages have the following extra context: status and request.
How do you get these to show up in the debug file? i tried in my logging config something like:
'formatters': {
'simple_debug': {
'format': '[%(asctime)s] %(levelname)s %(module)s %(message)s %(request.user)s',
}
},
but that causes the overall logging to fail (i.e. no logging output happens)
EDIT:
So immediately after submitting the question i came across this:
http://groups.google.com/group/django-users/browse_thread/thread/af682beb1e4af7f6/ace3338348e92a21
can someone help explain/elaborate on
All the quote from the docs really means is that all the places inside
of django where django.request is used, the request is explicitly
passed in as part of extra.
where is request explicitly passed in as part of extra to?
You can’t use
request.userin the format string, as %-formatting doesn’t handle that. You could use a format string such asand, in your logging call, use something like
The
extradict is merged into the logging event record, which ends up with auserattribute, and this then gets picked up through the format string and appears in the log.If using the
django.requestlogger, the status_code and the request will be passed in theextradict by Django. If you need therequest.user, you’ll probably need to add alogging.Filterwhich does something like:so that you can show the user in the formatted output.