Sha256: b601cb7896250d306f58da6a009a1d45ad09a014fd663a4888b5697409492ca2

Contents?: true

Size: 1.88 KB

Versions: 11

Compression:

Stored size: 1.88 KB

Contents

require 'colorize'

module Restly
  class LogSubscriber < ActiveSupport::LogSubscriber

    def request(event)
      event.payload[:color] ||= :light_green
      log_items = []
      log_items << event.payload[:name].colorize(event.payload[:color].to_sym)
      log_items << "(#{event.duration.round(1)} ms)"
      log_items << event.payload[:method].to_s.upcase.light_white
      log_items << event.payload[:url].light_white

      info "  " + log_items.join(" ")
    end

    def cache(event)
      event.payload[:color] ||= :green
      log_items = []
      log_items << event.payload[:name].colorize(event.payload[:color].to_sym)
      log_items << "(#{event.duration.round(1)} ms)"
      log_items << event.payload[:key].light_white

      info "  " + log_items.join(" ")
    end

    def load_collection(event)
      log_items = []
      log_items << "#{event.payload[:model]} Collection Load".blue
      log_items << "(#{event.duration.round(1)} ms)"

      info "  " + log_items.join(" ")
    end

    def missing_attribute(event)
      log_items = []
      log_items << "  WARNING: Attribute `#{event.payload[:attr]}` not written.".light_black
      log_items << "  To fix this add the following the the model --  field :#{event.payload[:attr]}".light_black

      warn log_items.join("\n")
    end

    def load_association(event)
      log_items = []
      log_items << "#{event.payload[:model]}##{event.payload[:association]} Association Load".cyan
      log_items << "(#{event.duration.round(1)} ms)"

      info "  " + log_items.join(" ")
    end

    def load_instance(event)
      log_items = []
      log_items << "#{event.payload[:instance].class.name} Instance Load".blue
      log_items << "(#{event.duration.round(1)} ms)"

      info "  " + log_items.join(" ") if event.payload[:instance].response
    end

    def logger
      Rails.logger
    end
  end
end

Restly::LogSubscriber.attach_to :restly

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
restly-0.0.1.beta.10 lib/restly/notifications.rb
restly-0.0.1.beta.9 lib/restly/notifications.rb
restly-0.0.1.beta.6 lib/restly/notifications.rb
restly-0.0.1.beta.5 lib/restly/notifications.rb
restly-0.0.1.beta.4 lib/restly/notifications.rb
restly-0.0.1.beta.3 lib/restly/notifications.rb
restly-0.0.1.beta.2 lib/restly/notifications.rb
restly-0.0.1.beta.1 lib/restly/notifications.rb
restly-0.0.1.alpha.22 lib/restly/notifications.rb
restly-0.0.1.alpha.19 lib/restly/notifications.rb
restly-0.0.1.alpha.18 lib/restly/notifications.rb