Module: NCore::LogSubscriber
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ncore/rails/log_subscriber.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEBUG_STATUSES =
(200..299).to_a + [404, 409, 422]
Instance Method Summary collapse
Instance Method Details
#log_request(event) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ncore/rails/log_subscriber.rb', line 31 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, :yellow) # for rails≤70, must exclude :bold param entirely since a Hash is truthy if (200..299).include? http_status res = color(res, :green, bold: true) else res = color(res, :red, bold: true) end if DEBUG_STATUSES.include? http_status debug " #{msg}" debug " #{res}" else error " #{msg}" error " #{res}" end end |