class DatastaxRails::Instrumentation::LogSubscriber
A log subscriber to attach to Datastax related events
@see github.com/rails/rails/blob/master/activerecord/lib/active_record/log_subscriber.rb
Public Class Methods
cql_runtime()
click to toggle source
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 25 def self.cql_runtime Thread.current['datastax_cql_runtime'] ||= 0 end
cql_runtime=(value)
click to toggle source
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 21 def self.cql_runtime=(value) Thread.current['datastax_cql_runtime'] = value end
new(*args)
click to toggle source
Calls superclass method
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 8 def initialize(*args) super @odd = false end
reset_cql_runtime()
click to toggle source
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 34 def self.reset_cql_runtime rt, self.cql_runtime = cql_runtime, 0 rt end
reset_solr_runtime()
click to toggle source
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 29 def self.reset_solr_runtime rt, self.solr_runtime = solr_runtime, 0 rt end
solr_runtime()
click to toggle source
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 17 def self.solr_runtime Thread.current['datastax_solr_runtime'] ||= 0 end
solr_runtime=(value)
click to toggle source
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 13 def self.solr_runtime=(value) Thread.current['datastax_solr_runtime'] = value end
Public Instance Methods
cql(event)
click to toggle source
Intercept `cql.datastax_rails` events, and display them in the Rails log
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 60 def cql(event) self.class.cql_runtime += event.duration return unless logger.debug? && DatastaxRails::Base.log_cql_queries payload = event.payload name = "#{payload[:klass]} #{payload[:name]} (#{event.duration.round(1)}ms)" cql = payload[:cql] binds = nil results = payload[:result_count] unless (payload[:binds] || []).empty? binds = ' ' + payload[:binds].inspect end if odd? name = color(name, CYAN, true) cql = color(cql, nil, true) else name = color(name, MAGENTA, true) end debug " #{name} #{cql}#{binds} - #{results} results" end
odd?()
click to toggle source
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 85 def odd? @odd = !@odd end
solr(event)
click to toggle source
Intercept `solr.datastax_rails` events, and display them in the Rails log
# File lib/datastax_rails/instrumentation/log_subscriber.rb, line 40 def solr(event) self.class.solr_runtime += event.duration return unless logger.debug? && DatastaxRails::Base.log_solr_queries payload = event.payload name = "#{payload[:klass]} #{payload[:name]} (#{event.duration.round(1)}ms)" search = payload[:search].inspect.gsub(/:(\w+)=>/, '\1: ') if odd? name = color(name, CYAN, true) search = color(search, nil, true) else name = color(name, MAGENTA, true) end debug " #{name} #{search}" end