Class: Timber::Events::HTTPServerResponse

Inherits:
Timber::Event
  • Object
show all
Defined in:
lib/timber/events/http_server_response.rb

Overview

Note:

This event should be installed automatically through integrations, such as the Integrations::ActionController::LogSubscriber integration.

The HTTP server response event tracks outgoing HTTP responses that you send to clients.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ HTTPServerResponse

Returns a new instance of HTTPServerResponse.



11
12
13
14
15
16
17
# File 'lib/timber/events/http_server_response.rb', line 11

def initialize(attributes)
  @headers = Util::HTTPEvent.normalize_headers(attributes[:headers])
  @request_id = attributes[:request_id]
  @status = attributes[:status] || raise(ArgumentError.new(":status is required"))
  @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required"))
  @time_ms = @time_ms.round(6)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/timber/events/http_server_response.rb', line 9

def headers
  @headers
end

#request_idObject (readonly)

Returns the value of attribute request_id.



9
10
11
# File 'lib/timber/events/http_server_response.rb', line 9

def request_id
  @request_id
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/timber/events/http_server_response.rb', line 9

def status
  @status
end

#time_msObject (readonly)

Returns the value of attribute time_ms.



9
10
11
# File 'lib/timber/events/http_server_response.rb', line 9

def time_ms
  @time_ms
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



24
25
26
# File 'lib/timber/events/http_server_response.rb', line 24

def as_json(_options = {})
  {:http_server_response => to_hash}
end

#messageObject



28
29
30
# File 'lib/timber/events/http_server_response.rb', line 28

def message
  "Completed #{status} #{status_description} in #{time_ms}ms"
end

#status_descriptionObject



32
33
34
# File 'lib/timber/events/http_server_response.rb', line 32

def status_description
  Rack::Utils::HTTP_STATUS_CODES[status]
end

#to_hashObject Also known as: to_h



19
20
21
# File 'lib/timber/events/http_server_response.rb', line 19

def to_hash
  {headers: headers, request_id: request_id, status: status, time_ms: time_ms}
end