Class: Sunspot::Rails::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/sunspot/rails/log_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_runtimeObject



12
13
14
15
# File 'lib/sunspot/rails/log_subscriber.rb', line 12

def self.reset_runtime
  rt, self.runtime = runtime, 0
  rt
end

.runtimeObject



8
9
10
# File 'lib/sunspot/rails/log_subscriber.rb', line 8

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

.runtime=(value) ⇒ Object



4
5
6
# File 'lib/sunspot/rails/log_subscriber.rb', line 4

def self.runtime=(value)
  Thread.current["sorl_runtime"] = value
end

Instance Method Details

#request(event) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sunspot/rails/log_subscriber.rb', line 17

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