Create a dictionary with logging data.

def create_log_dict(request, response):
    """
    Create a dictionary with logging data.
    """
    remote_addr = request.META.get('REMOTE_ADDR')
    if remote_addr in getattr(settings, 'INTERNAL_IPS', []):
        remote_addr = request.META.get(
            'HTTP_X_FORWARDED_FOR') or remote_addr

    user_email = "-"
    if hasattr(request, 'user'):
        user_email = getattr(request.user, 'email', '-')

    if response.streaming:
        content_length = 'streaming'
    else:
        content_length = len(response.content)

    return {
        # 'event' makes event-based filtering possible in logging backends
        # like logstash
        'event': settings.LOGUTILS_LOGGING_MIDDLEWARE_EVENT,
        'remote_address': remote_addr,
        'user_email': user_email,
        'method': request.method,
        'url': request.get_full_path(),
        'status': response.status_code,
        'content_length': content_length,
        'request_time': -1,  # NA value: real value added by LoggingMiddleware
    }