I have a specific view in my app which should return HttpResponse('')
if everything was done successfully and smth like HttpResponseBadRequest()
otherwise.
This view works with external data so some unexpected exceptions can be raised. Of course I need to know what happened. So I have smth like that:
def my_view(request):
try:
# a lot of code
return HttpResponse('')
except:
import logging
logger = logging.getLogger('django.request')
# logger.error(extra={'request': request}) or logger.exception()
return HttpResponseBadRequest('')
I have a default logging config if it matters (django 1.5).
logger.exception
sends only a small traceback and no request data.
logger.error
sends only request data.
So the question is how to get exactly the same traceback as django sends (with the same subject/body)). I think there must be some clean and simple solution that i just can't find.
UPDATE
So with the patched exception
method i ended up with the following code:
logger.exception('Internal Server Error: %s', request.path,
extra={'status_code': 500, 'request': request})
which produces equal email traceback as built-in django logging.