Log an event from the client to the server.

    POST parameters (JSON keys):
      message:
        description (str) of the logged event
      level:
        debug|info|warn|error
      data:
        additional data (JSON) describing the logged event

def log(request):
    """
    Log an event from the client to the server.

    POST parameters (JSON keys):
      message:
        description (str) of the logged event
      level:
        debug|info|warn|error
      data:
        additional data (JSON) describing the logged event
    """
    if request.method == "POST":
        log_dict = json_body(request.body.decode("utf-8"))
        if 'message' not in log_dict:
            return HttpResponseBadRequest('There is no message to log!')
        levels = {
            'debug': JAVASCRIPT_LOGGER.debug,
            'info': JAVASCRIPT_LOGGER.info,
            'warn': JAVASCRIPT_LOGGER.warn,
            'error': JAVASCRIPT_LOGGER.error,
        }
        log_fun = JAVASCRIPT_LOGGER.info
        if 'level' in log_dict:
            log_fun = levels[log_dict['level']]
        log_fun(log_dict['message'], extra={
            'request': request,
            'user': request.user.id if request.user.is_authenticated() else None,
            'client_data': json_lib.dumps(log_dict.get('data', {})),
        })
        return HttpResponse('ok', status=201)
    else:
        return render_json(request, {}, template='common_log_service.html', help_text=log.__doc__)