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
35 36 37 38 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 35 def self.reset_runtime rt, self.runtime = runtime, 0 rt end |
.runtime ⇒ Object
31 32 33 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 31 def self.runtime Thread.current["elasticsearch_runtime"] ||= 0 end |
.runtime=(value) ⇒ Object
27 28 29 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 27 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
42 43 44 45 46 47 48 49 50 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 42 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 |