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
18 19 20 21 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 18 def self.reset_runtime rt, self.runtime = runtime, 0 rt end |
.runtime ⇒ Object
14 15 16 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 14 def self.runtime Thread.current["elasticsearch_runtime"] ||= 0 end |
.runtime=(value) ⇒ Object
10 11 12 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 10 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
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elasticsearch/rails/instrumentation/log_subscriber.rb', line 25 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, true)} #{colorize_logging ? "\e[2m#{search}\e[0m" : search}| end |