示例#1
0
    def format(self, record):
        utcnow = datetime.utcnow()
        request = record.request_info.request
        request_adapter = _request_util.request_adapter

        length = request_adapter.get_content_length(request)
        json_log_object = {
            "type": "request",
            "written_at": util.iso_time_format(utcnow),
            "written_ts": util.epoch_nano_second(utcnow),
            "component_id": COMPONENT_ID,
            "component_name": COMPONENT_NAME,
            "component_instance": COMPONENT_INSTANCE_INDEX,
            "correlation_id": _request_util.get_correlation_id(request),
            "remote_user": request_adapter.get_remote_user(request),
            "request": request_adapter.get_path(request),
            "referer": request_adapter.get_http_header(request, 'referer', EMPTY_VALUE),
            "x_forwarded_for": request_adapter.get_http_header(request, 'x-forwarded-for', EMPTY_VALUE),
            "protocol": request_adapter.get_protocol(request),
            "method": request_adapter.get_method(request),
            "remote_ip": request_adapter.get_remote_ip(request),
            "request_size_b": util.parse_int(length, -1),
            "remote_host": request_adapter.get_remote_ip(request),
            "remote_port": request_adapter.get_remote_port(request),
            "request_received_at": record.request_info.request_received_at,
            "response_time_ms": record.request_info.response_time_ms,
            "response_status": record.request_info.response_status,
            "response_size_b": record.request_info.response_size_b,
            "response_content_type": record.request_info.response_content_type,
            "response_sent_at": record.request_info.response_sent_at}
        return JSON_SERIALIZER(json_log_object)
示例#2
0
    def format(self, record):
        utcnow = datetime.utcnow()
        json_log_object = {
            "type": "log",
            "written_at": util.iso_time_format(utcnow),
            "written_ts": util.epoch_nano_second(utcnow),
            "component_id": COMPONENT_ID,
            "component_name": COMPONENT_NAME,
            "component_instance": COMPONENT_INSTANCE_INDEX,
            "logger": record.name,
            "thread": record.threadName,
            "level": record.levelname,
            "module": record.module,
            "line_no": record.lineno,
            "correlation_id": _request_util.get_correlation_id(),
            "msg": record.getMessage()
        }

        if hasattr(record, 'props'):
            json_log_object.update(record.props)

        if record.exc_info or record.exc_text:
            json_log_object.update(self.get_exc_fields(record))

        return JSON_SERIALIZER(json_log_object)
示例#3
0
 def _format_log_object(self, record, request_util):
     utcnow = datetime.utcnow()
     base_obj = {
         "written_at": util.iso_time_format(utcnow),
         "written_ts": util.epoch_nano_second(utcnow),
     }
     base_obj.update(self.base_object_common)
     return base_obj
 def on_request_complete(self, response):
     super(DefaultRequestResponseDTO, self).on_request_complete(response)
     utcnow = datetime.utcnow()
     time_delta = utcnow - self._request_start
     self["response_time_ms"] = int(
         time_delta.total_seconds()) * 1000 + int(
             time_delta.microseconds / 1000)
     self["response_sent_at"] = util.iso_time_format(utcnow)
示例#5
0
 def update_response_status(self, response):
     """
     update response information into this object, must be called before invoke request logging statement
     :param response:
     """
     response_adapter = _request_util.response_adapter
     utcnow = datetime.utcnow()
     time_delta = utcnow - self.request_start
     self.response_time_ms = int(time_delta.total_seconds()) * 1000 + int(time_delta.microseconds / 1000)
     self.response_status = response_adapter.get_status_code(response)
     self.response_size_b = response_adapter.get_response_size(response)
     self.response_content_type = response_adapter.get_content_type(response)
     self.response_sent_at = util.iso_time_format(utcnow)
示例#6
0
 def __init__(self, request, **kwargs):
     super(self.__class__, self).__init__(**kwargs)
     utcnow = datetime.utcnow()
     self.request_start = utcnow
     self.request = request
     self.request_received_at = util.iso_time_format(utcnow)
 def __init__(self, request, **kwargs):
     super(DefaultRequestResponseDTO, self).__init__(request, **kwargs)
     utcnow = datetime.utcnow()
     self._request_start = utcnow
     self["request_received_at"] = util.iso_time_format(utcnow)