I have a specific view in my application that should return HttpResponse('')if everything was successful and smth as HttpResponseBadRequest()otherwise.
This view works with external data, so some unexpected exceptions may occur. Of course I need to know what happened. So I have something like:
def my_view(request):
try:
return HttpResponse('')
except:
import logging
logger = logging.getLogger('django.request')
return HttpResponseBadRequest('')
I have a default registration configuration if that matters (django 1.5).
logger.exceptionsends only a small trace and request data.
logger.errorsends only request data.
So the question is how to get exactly the same trace as sending django (with the same item / body)). I think there must be some kind of clean and simple solution that I just cannot find.
UPDATE
So, using the corrected method exception, I got the following code:
logger.exception('Internal Server Error: %s', request.path,
extra={'status_code': 500, 'request': request})
which creates equal email tracing as an inline entry in django.
alTus source
share