Class: RemoteResource::LogSubscriber

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

Instance Method Summary collapse

Instance Method Details

#find(event) ⇒ Object



9
10
11
# File 'lib/remote_resource/log_subscriber.rb', line 9

def find(event)
  log_action('Find', event)
end

#http_get(event) ⇒ Object



17
18
19
# File 'lib/remote_resource/log_subscriber.rb', line 17

def http_get(event)
  log_action('HTTP GET', event) { |payload| payload[:attribute] }
end

#log_action(action, event, &block) ⇒ Object

the optional block acts as a filter for the log description. The block is passed the payload and its return value is used as the log description. The whole payload is used as the description if the block is omitted.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/remote_resource/log_subscriber.rb', line 24

def log_action(action, event, &block)
  payload = event.payload
  description = block ? block.call(payload) : payload

  if (attribute = payload[:attribute])
    subject = attribute[:location]
    action = "#{subject} #{action} (#{event.duration.round(2)}ms)"
  end

  action = color(action, GREEN, true)
  debug("#{action} #{description}")
end

#loggerObject



5
6
7
# File 'lib/remote_resource/log_subscriber.rb', line 5

def logger
  RemoteResource.logger
end

#storage_lookup(event) ⇒ Object



13
14
15
# File 'lib/remote_resource/log_subscriber.rb', line 13

def storage_lookup(event)
  log_action('Storage lookup', event) { |payload| payload[:attribute] }
end