Class: Timber::Events::HTTPResponse
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::HTTPResponse
- Defined in:
- lib/timber/events/http_response.rb
Overview
Note:
This event should be installed automatically through probes, such as the Probes::ActionControllerLogSubscriber probe.
The HTTP response event tracks outgoing HTTP request responses.
Instance Attribute Summary collapse
-
#additions ⇒ Object
readonly
Returns the value of attribute additions.
-
#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) ⇒ HTTPResponse
constructor
A new instance of HTTPResponse.
- #message ⇒ Object
- #status_description ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(attributes) ⇒ HTTPResponse
Returns a new instance of HTTPResponse.
10 11 12 13 14 |
# File 'lib/timber/events/http_response.rb', line 10 def initialize(attributes) @status = attributes[:status] || raise(ArgumentError.new(":status is required")) @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required")) @additions = attributes[:additions] end |
Instance Attribute Details
#additions ⇒ Object (readonly)
Returns the value of attribute additions.
8 9 10 |
# File 'lib/timber/events/http_response.rb', line 8 def additions @additions end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/timber/events/http_response.rb', line 8 def status @status end |
#time_ms ⇒ Object (readonly)
Returns the value of attribute time_ms.
8 9 10 |
# File 'lib/timber/events/http_response.rb', line 8 def time_ms @time_ms end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
21 22 23 |
# File 'lib/timber/events/http_response.rb', line 21 def as_json( = {}) {:http_response => to_hash} end |
#message ⇒ Object
25 26 27 28 29 |
# File 'lib/timber/events/http_response.rb', line 25 def = "Completed #{status} #{status_description} in #{time_ms}ms" << " (#{additions.join(" | ".freeze)})" unless additions.empty? end |
#status_description ⇒ Object
31 32 33 |
# File 'lib/timber/events/http_response.rb', line 31 def status_description Rack::Utils::HTTP_STATUS_CODES[status] end |
#to_hash ⇒ Object Also known as: to_h
16 17 18 |
# File 'lib/timber/events/http_response.rb', line 16 def to_hash {status: status, time_ms: time_ms} end |