Class: Searchkick::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Searchkick::LogSubscriber
- Defined in:
- lib/searchkick/logging.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.reset_runtime ⇒ Object
61 62 63 64 65 |
# File 'lib/searchkick/logging.rb', line 61 def self.reset_runtime rt = runtime self.runtime = 0 rt end |
.runtime ⇒ Object
57 58 59 |
# File 'lib/searchkick/logging.rb', line 57 def self.runtime Thread.current[:searchkick_runtime] ||= 0 end |
.runtime=(value) ⇒ Object
53 54 55 |
# File 'lib/searchkick/logging.rb', line 53 def self.runtime=(value) Thread.current[:searchkick_runtime] = value end |
Instance Method Details
#request(event) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/searchkick/logging.rb', line 81 def request(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload name = "#{payload[:name]} (#{event.duration.round(1)}ms)" debug " #{color(name, YELLOW, true)} #{payload.except(:name).to_json}" end |
#search(event) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/searchkick/logging.rb', line 67 def search(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload name = "#{payload[:name]} (#{event.duration.round(1)}ms)" type = payload[:query][:type] index = payload[:query][:index].is_a?(Array) ? payload[:query][:index].join(",") : payload[:query][:index] # no easy way to tell which host the client will use host = Searchkick.client.transport.hosts.first debug " #{color(name, YELLOW, true)} curl #{host[:protocol]}://#{host[:host]}:#{host[:port]}/#{CGI.escape(index)}#{type ? "/#{type.map { |t| CGI.escape(t) }.join(',')}" : ''}/_search?pretty -d '#{payload[:query][:body].to_json}'" end |