Class: Timber::Events::HTTPServerResponse
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::HTTPServerResponse
- 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
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#time_ms ⇒ Object
readonly
Returns the value of attribute time_ms.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ HTTPServerResponse
constructor
A new instance of HTTPServerResponse.
- #message ⇒ Object
- #status_description ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
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
#headers ⇒ Object (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_id ⇒ Object (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 |
#status ⇒ Object (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_ms ⇒ Object (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( = {}) {:http_server_response => to_hash} end |
#message ⇒ Object
28 29 30 |
# File 'lib/timber/events/http_server_response.rb', line 28 def "Completed #{status} #{status_description} in #{time_ms}ms" end |
#status_description ⇒ Object
32 33 34 |
# File 'lib/timber/events/http_server_response.rb', line 32 def status_description Rack::Utils::HTTP_STATUS_CODES[status] end |
#to_hash ⇒ Object 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 |