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

.loggerObject



21
22
23
# File 'lib/sunspot/rails/log_subscriber.rb', line 21

def self.logger
  @logger if defined?(@logger)
end

.logger=(logger) ⇒ Object



17
18
19
# File 'lib/sunspot/rails/log_subscriber.rb', line 17

def self.logger=(logger)
  @logger = logger
end

.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

#loggerObject



25
26
27
# File 'lib/sunspot/rails/log_subscriber.rb', line 25

def logger
  self.class.logger || ::Rails.logger
end

#request(event) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sunspot/rails/log_subscriber.rb', line 29

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], nil, 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, nil, bold: true)}"
  }.join(', ')
  request = "path=#{path} parameters={#{parameters}}"

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