Class: Elasticsearch::Rails::Instrumentation::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Elasticsearch::Rails::Instrumentation::LogSubscriber
- Defined in:
- lib/elasticsearch/rails/instrumentation/log_subscriber.rb
Overview
A log subscriber to attach to Elasticsearch related events
Class Method Summary collapse
Instance Method Summary collapse
-
#search(event) ⇒ Object
Intercept ‘search.elasticsearch` events, and display them in the Rails log.
Class Method Details
.reset_runtime ⇒ Object
34 35 36 37 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 34 def self.reset_runtime rt, self.runtime = runtime, 0 rt end |
.runtime ⇒ Object
30 31 32 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 30 def self.runtime Thread.current["elasticsearch_runtime"] ||= 0 end |
.runtime=(value) ⇒ Object
26 27 28 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 26 def self.runtime=(value) Thread.current["elasticsearch_runtime"] = value end |
Instance Method Details
#search(event) ⇒ Object
Intercept ‘search.elasticsearch` events, and display them in the Rails log
41 42 43 44 45 46 47 48 49 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 41 def search(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload name = "#{payload[:klass]} #{payload[:name]} (#{event.duration.round(1)}ms)" search = payload[:search].inspect.gsub(/:(\w+)=>/, '\1: ') debug %Q| #{color(name, GREEN, color_option(true))} #{colorize_logging ? "\e[2m#{search}\e[0m" : search}| end |