How to send Django event log manually?

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:
        # 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 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.

+4
source share
1 answer

This issue is due to a bug fixed in recent versions of Python 2.7. This error meant that the method exceptiondid not accept the argument extra.

Python 2.7, , , Python , , . , Logger exception, ( **kwargs exception, error.

+3

All Articles