Class: Searchkick::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/searchkick/logging.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_runtimeObject



153
154
155
156
157
# File 'lib/searchkick/logging.rb', line 153

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

.runtimeObject



149
150
151
# File 'lib/searchkick/logging.rb', line 149

def self.runtime
  Thread.current[:searchkick_runtime] ||= 0
end

.runtime=(value) ⇒ Object



145
146
147
# File 'lib/searchkick/logging.rb', line 145

def self.runtime=(value)
  Thread.current[:searchkick_runtime] = value
end

Instance Method Details

#multi_search(event) ⇒ Object



188
189
190
191
192
193
194
195
196
# File 'lib/searchkick/logging.rb', line 188

def multi_search(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)}  _msearch #{payload[:body]}"
end

#request(event) ⇒ Object



178
179
180
181
182
183
184
185
186
# File 'lib/searchkick/logging.rb', line 178

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



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/searchkick/logging.rb', line 159

def search(event)
  self.class.runtime += event.duration
  return unless logger.debug?

  payload = event.payload
  name = "#{payload[:name]} (#{event.duration.round(1)}ms)"

  index = payload[:query][:index].is_a?(Array) ? payload[:query][:index].join(",") : payload[:query][:index]
  type = payload[:query][:type]
  request_params = payload[:query].except(:index, :type, :body)

  params = []
  request_params.each do |k, v|
    params << "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
  end

  debug "  #{color(name, YELLOW, true)}  #{index}#{type ? "/#{type.join(',')}" : ''}/_search#{params.any? ? '?' + params.join('&') : nil} #{payload[:query][:body].to_json}"
end