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.
10 11 12 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 10 def initialize(logger) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 8 def logger @logger end |
Instance Method Details
#generate_log_message(event) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 20 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
14 15 16 17 18 |
# File 'lib/client_api_builder/active_support_log_subscriber.rb', line 14 def subscribe! ActiveSupport::Notifications.subscribe('client_api_builder.request') do |event| logger.info((event)) end end |