Module: Sunspot::Rails::SolrLogging

Defined in:
lib/sunspot/rails/solr_logging.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/sunspot/rails/solr_logging.rb', line 5

def included(base)
  base.module_eval { alias_method_chain(:request, :rails_logging) }
end

Instance Method Details

#request_with_rails_logging(path, params = {}, *extra) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sunspot/rails/solr_logging.rb', line 10

def request_with_rails_logging(path, params={}, *extra)

  # Set up logging text.
  body = (params.nil? || params.empty?) ? extra.first : params.inspect
  action = path[1..-1].capitalize
  if body == "<commit/>"
    action = 'Commit'
    body = ''
  end
  body = body[0, 800] + '...' if body.length > 800

  # Make request and log.
  response = nil
  begin
    ms = Benchmark.ms do
      response = request_without_rails_logging(path, params, *extra)
    end
    log_name = 'Solr %s (%.1fms)' % [action, ms]
    ::Rails.logger.debug(format_log_entry(log_name, body))
  rescue Exception => e
    log_name = 'Solr %s (Error)' % [action]
    ::Rails.logger.error(format_log_entry(log_name, body))
    raise e
  end

  response
end