Class: Chewy::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/chewy/log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#delete_query(event) ⇒ Object



15
16
17
# File 'lib/chewy/log_subscriber.rb', line 15

def delete_query(event)
  render_action('Delete by Query', event) { |payload| payload[:request] }
end

#import_objects(event) ⇒ Object



7
8
9
# File 'lib/chewy/log_subscriber.rb', line 7

def import_objects(event)
  render_action('Import', event) { |payload| payload[:import] }
end

#loggerObject



3
4
5
# File 'lib/chewy/log_subscriber.rb', line 3

def logger
  Chewy.logger
end

#render_action(action, event) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chewy/log_subscriber.rb', line 19

def render_action(action, event)
  payload = event.payload
  description = yield(payload)

  return if description.blank?

  subject = payload[:type].presence || payload[:index]
  action = "#{subject} #{action} (#{event.duration.round(1)}ms)"
  action = if ActiveSupport.version >= Gem::Version.new('7.1')
    color(action, GREEN, bold: true)
  else
    color(action, GREEN, true)
  end

  debug("  #{action} #{description}")
end

#search_query(event) ⇒ Object



11
12
13
# File 'lib/chewy/log_subscriber.rb', line 11

def search_query(event)
  render_action('Search', event) { |payload| payload[:request] }
end