Class: GarageClient::Rails::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/garage_client/rails/log_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_runtimeObject



14
15
16
17
# File 'lib/garage_client/rails/log_subscriber.rb', line 14

def self.reset_runtime
  rt, self.runtime = runtime, 0
  rt
end

.runtimeObject



10
11
12
# File 'lib/garage_client/rails/log_subscriber.rb', line 10

def self.runtime
  GarageClient::Rails::RuntimeRegistry.garage_client_runtime ||= 0
end

.runtime=(value) ⇒ Object



6
7
8
# File 'lib/garage_client/rails/log_subscriber.rb', line 6

def self.runtime=(value)
  GarageClient::Rails::RuntimeRegistry.garage_client_runtime = value
end

Instance Method Details

#request(event) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/garage_client/rails/log_subscriber.rb', line 19

def request(event)
  return if logger.nil?
  return unless logger.debug?

  self.class.runtime += event.duration

  payload = event.payload

  name   = color("GarageClient (#{event.duration.round(1)}ms)", GREEN, true)
  method = color(payload[:method].to_s.upcase, WHITE, true)
  url    = color(payload[:url], WHITE, true)
  body   = (payload[:body].nil? ? nil : color(payload[:body], WHITE, false))

  message = ""
  message << "  #{name} #{method} #{url}"
  unless body.blank?
    message << " body=#{body}"
  end

  debug(message)
end