Module: NCore::LogSubscriber

Extended by:
ActiveSupport::Concern
Defined in:
lib/ncore/rails/log_subscriber.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#log_request(event) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ncore/rails/log_subscriber.rb', line 29

def log_request(event)
  self.class.runtime += event.duration

  env = event.payload
  url = env[:url].to_s
  http_method = env[:method].to_s.upcase
  http_status = env[:status] || -1

  msg = "%s %s" % [http_method, url]
  res = " -> %d (%.1f ms)" % [http_status, event.duration]

  msg = color(msg, ActiveSupport::LogSubscriber::YELLOW, false)
  if (200..299).include? http_status
    res = color(res, ActiveSupport::LogSubscriber::GREEN, true)
  else
    res = color(res, ActiveSupport::LogSubscriber::RED, true)
  end

  if (200..299).include? http_status
    debug "  #{msg}"
    debug "  #{res}"
  else
    error "  #{msg}"
    error "  #{res}"
  end
end