Sha256: f3e977bcbcdfeb90f803ed4fa33928cf3d90e6b675c2ee3fbc94e9fc0977c0c9

Contents?: true

Size: 1.31 KB

Versions: 16

Compression:

Stored size: 1.31 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 if defined?(@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: "edismax", start: 0, rows: 20}
        path = color(event.payload[:path], BOLD, true)
        parameters = event.payload[:parameters].map { |k, v|
          v = "\"#{v}\"" if v.is_a? String
          v = v.to_s.gsub(/\\/,'') # unescape
          "#{k}: #{color(v, BOLD, true)}"
        }.join(', ')
        request = "path=#{path} parameters={#{parameters}}"

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

Sunspot::Rails::LogSubscriber.attach_to :rsolr

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
sunspot_rails-2.6.0 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.5.0 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.4.0 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.3.0 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.8 lib/sunspot/rails/log_subscriber.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot_rails-2.2.7/lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.7 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.6 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.5 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.4 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.3 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.2 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.1 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.2.0 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.1.1 lib/sunspot/rails/log_subscriber.rb
sunspot_rails-2.1.0 lib/sunspot/rails/log_subscriber.rb