Class: GeckoLogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- GeckoLogSubscriber
- Defined in:
- lib/gecko/ext/log_subscriber.rb
Overview
Requiring this file, or calling ‘Gecko.enable_logging` will hook into the provided ActiveSupport::Notification hooks on requests and log ActiveRecord-style messages on API requests.
Constant Summary collapse
- ENV_KEY =
:"gecko-logger"
Instance Method Summary collapse
-
#initialize ⇒ GeckoLogSubscriber
constructor
A new instance of GeckoLogSubscriber.
- #odd? ⇒ Boolean
-
#request(event) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Constructor Details
#initialize ⇒ GeckoLogSubscriber
Returns a new instance of GeckoLogSubscriber.
11 12 13 14 |
# File 'lib/gecko/ext/log_subscriber.rb', line 11 def initialize super @odd = false end |
Instance Method Details
#odd? ⇒ Boolean
41 42 43 |
# File 'lib/gecko/ext/log_subscriber.rb', line 41 def odd? @odd = !@odd end |
#request(event) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gecko/ext/log_subscriber.rb', line 16 def request(event) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength RequestStore.store[ENV_KEY] = [] payload = event.payload request_path = payload[:request_path] if payload[:params] && payload[:verb] == :get request_path = request_path + "?" + payload[:params].to_param RequestStore.store[ENV_KEY] << request_path end name = "#{payload[:model_class]} Load (#{event.duration.round(1)}ms)" query = "#{payload[:verb].to_s.upcase} /#{request_path}" name = if odd? color(name, CYAN, true) else color(name, MAGENTA, true) end query = color(query, nil, true) debug(" #{name} #{query}") end |