Sha256: 670595068d1578ac664342a4462619cefb7a810cd6bdea0be33e82f2849be414

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Sunspot
  module Rails
    class LogSubscriber < ActiveSupport::LogSubscriber
      def self.runtime=(value)
        Thread.current["sorl_runtime"] = value
      end

      def self.runtime
        Thread.current["sorl_runtime"] ||= 0
      end

      def self.reset_runtime
        rt, self.runtime = runtime, 0
        rt
      end
      
      def self.logger=(logger)
        @logger = logger
      end
      
      def self.logger
        @logger
      end
      
      def logger
        self.class.logger || ::Rails.logger
      end

      def request(event)
        self.class.runtime += event.duration
        return unless logger.debug?

        name = '%s (%.1fms)' % ["SOLR Request", event.duration]

        # produces: path=/select parameters={fq: ["type:Tag"], q: rossi, fl: * score, qf: tag_name_text, defType: dismax, start: 0, rows: 20}
        parameters = event.payload[:parameters].map { |k, v| "#{k}: #{color(v, BOLD, true)}" }.join(', ')
        request = "path=#{event.payload[:path]} parameters={#{parameters}}"

        debug "  #{color(name, GREEN, true)}  [ #{request} ]"
      end
    end
  end
end

Sunspot::Rails::LogSubscriber.attach_to :rsolr

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
sunspot_rails-2.0.0.pre.120925 lib/sunspot/rails/log_subscriber.rb
sunspot_solr-2.0.0.pre.120924 sunspot_rails/lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.0.0.pre.120924 sunspot_rails/lib/sunspot/rails/log_subscriber.rb
sunspot-2.0.0.pre.120924 sunspot_rails/lib/sunspot/rails/log_subscriber.rb