Class: ClientApiBuilder::ActiveSupportLogSubscriber
- Inherits:
-
Object
- Object
- ClientApiBuilder::ActiveSupportLogSubscriber
- Defined in:
- lib/client_api_builder/active_support_log_subscriber.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #generate_log_message(event) ⇒ Object
-
#initialize(logger) ⇒ ActiveSupportLogSubscriber
constructor
A new instance of ActiveSupportLogSubscriber.
- #subscribe! ⇒ Object
Constructor Details
#initialize(logger) ⇒ ActiveSupportLogSubscriber
Returns a new instance of ActiveSupportLogSubscriber.
9 10 11 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 9 def initialize(logger) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 7 def logger @logger end |
Instance Method Details
#generate_log_message(event) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 19 def (event) client = event.payload[:client] method = client.[:method].to_s.upcase uri = client.[:uri] response = client.response response_code = response ? response.code : 'UNKNOWN' "#{method} #{uri.scheme}://#{uri.host}#{uri.path}[#{response_code}] took #{event.duration.to_i}ms" end |
#subscribe! ⇒ Object
13 14 15 16 17 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 13 def subscribe! ActiveSupport::Notifications.subscribe('client_api_builder.request') do |event| logger.info((event)) end end |