Module: Sunspot::Rails::SolrLogging

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

Constant Summary collapse

COMMIT =
%r{<commit/>}

Instance Method Summary collapse

Instance Method Details

#execute_with_rails_logging(request_context) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sunspot/rails/solr_logging.rb', line 7

def execute_with_rails_logging(request_context)
  body = (request_context[:data]||"").dup
  action = request_context[:path].capitalize
  if body =~ COMMIT
    action = "Commit"
    body = ""
  end

  # Make request and log.
  response = nil
  begin
    ms = Benchmark.ms do
      response = execute_without_rails_logging(request_context)
    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