Automated request exception logging.

    The function can also return an WSGIRequest exception,
    which does not supply either status_code or reason_phrase.

def request_exception(sender, request, **kwargs):
    """
    Automated request exception logging.

    The function can also return an WSGIRequest exception,
    which does not supply either status_code or reason_phrase.
    """
    if not isinstance(request, WSGIRequest):
        logger = logging.getLogger(__name__)
        level = CRITICAL if request.status_code <= 500 else WARNING

        logger.log(level, '%s exception occured (%s)',
                   request.status_code, request.reason_phrase)

    else:
        logger = logging.getLogger(__name__)
        logger.log(WARNING, 'WSGIResponse exception occured')