Class: ThinkingSphinx::ActiveRecord::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- ThinkingSphinx::ActiveRecord::LogSubscriber
- Defined in:
- lib/thinking_sphinx/active_record/log_subscriber.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ LogSubscriber
constructor
A new instance of LogSubscriber.
- #logger ⇒ Object
- #logger=(logger) ⇒ Object
- #message(event) ⇒ Object
- #odd? ⇒ Boolean
- #query(event) ⇒ Object
Constructor Details
#initialize ⇒ LogSubscriber
Returns a new instance of LogSubscriber.
19 20 21 22 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 19 def initialize super @odd_or_even = false end |
Class Method Details
.reset_runtime ⇒ Object
14 15 16 17 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 14 def self.reset_runtime rt, self.runtime = runtime, 0 rt end |
.runtime ⇒ Object
10 11 12 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 10 def self.runtime Thread.current['thinking_sphinx_query_runtime'] ||= 0 end |
.runtime=(value) ⇒ Object
6 7 8 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 6 def self.runtime=(value) Thread.current['thinking_sphinx_query_runtime'] = value end |
Instance Method Details
#logger ⇒ Object
49 50 51 52 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 49 def logger return @logger if defined? @logger self.logger = ::ActiveRecord::Base.logger end |
#logger=(logger) ⇒ Object
54 55 56 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 54 def logger=(logger) @logger = logger end |
#message(event) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 35 def (event) return unless logger.debug? identifier = color 'Sphinx', GREEN, true = event.payload[:message] = color , nil, true if odd? debug " #{identifier} #{}" end |
#odd? ⇒ Boolean
45 46 47 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 45 def odd? @odd_or_even = !@odd_or_even end |
#query(event) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/thinking_sphinx/active_record/log_subscriber.rb', line 24 def query(event) self.class.runtime += event.duration return unless logger.debug? identifier = color('Sphinx Query (%.1fms)' % event.duration, GREEN, true) query = event.payload[:query] query = color query, nil, true if odd? debug " #{identifier} #{query}" end |