Пример #1
0
    def process_request(self, request):

        request_path = request.path
        req = RequestLog(
            requested_url=request.build_absolute_uri(request_path),
            datetime=datetime.now(),
            request_type=request.method,
            request_ip=request.META['REMOTE_ADDR'],
        )
        req.save()
Пример #2
0
def create_request_response_log(sender, **extra):
    r = RequestLog()
    r.request_url = request.base_url
    r.request_resource = request.path

    parameters = request.values.to_dict()
    r.request_oauth_parameters = {}
    for k in parameters.keys():
        if k.startswith("oauth_"):
            r.request_oauth_parameters[k] = parameters.pop(k)
    r.request_parameters = parameters
    r.request_method = request.method
    r.put()

    g.request_log = r
Пример #3
0
    def process_exception(self, request, exception):
        extra = {}
        logging.error("An unhandled exception occurred: %s" % repr(exception),
                      extra=extra)

        time_taken = -1
        if hasattr(request, LOGGING_START_TIME_ATTR):
            start = getattr(request, LOGGING_START_TIME_ATTR)
            time_taken = time.time() - start

        records = self._handler.get_records()
        first = records[0] if len(records) > 0 else None
        records = [self._record_to_json(record, first) for record in records]
        message = json.dumps(records)

        log_entry = RequestLog(uri=request.path,
                               message=message,
                               duration=time_taken)
        log_entry.save()
Пример #4
0
    def process_response(self, request, response):
        
        if not hasattr(request, LOGGING_ENABLE_ATTR):
            return response
        
        time_taken = -1
        if hasattr(request, LOGGING_START_TIME_ATTR):
            start = getattr(request, LOGGING_START_TIME_ATTR)
            time_taken = time.time() - start

        records = self._handler.get_records()
        first = records[0] if len(records) > 0 else None
        records = [self._record_to_json(record, first) for record in records]
        message = json.dumps(records)

        log_entry = RequestLog(uri=request.path,
                               message = message,
                               duration=time_taken)
        log_entry.save()

        return response