Class: Sunspot::Rails::LogSubscriber

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) reset_runtime



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

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

+ (Object) runtime



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

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

+ (Object) runtime=(value)



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

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

Instance Method Details

- (Object) request(event)



17
18
19
20
21
22
23
24
25
26
27
28
# File 'sunspot_rails/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