Class: SequelRails::Railties::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- SequelRails::Railties::LogSubscriber
- Defined in:
- lib/sequel_rails/railties/log_subscriber.rb
Class Method Summary collapse
- .count ⇒ Object
- .count=(value) ⇒ Object
- .reset_count ⇒ Object
- .reset_runtime ⇒ Object
- .runtime ⇒ Object
- .runtime=(value) ⇒ Object
Instance Method Summary collapse
Class Method Details
.count ⇒ Object
16 17 18 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 16 def self.count Thread.current['sequel_sql_count'] ||= 0 end |
.count=(value) ⇒ Object
12 13 14 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 12 def self.count=(value) Thread.current['sequel_sql_count'] = value end |
.reset_count ⇒ Object
26 27 28 29 30 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 26 def self.reset_count previous = count self.count = 0 previous end |
.reset_runtime ⇒ Object
20 21 22 23 24 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 20 def self.reset_runtime previous = runtime self.runtime = 0 previous end |
.runtime ⇒ Object
8 9 10 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 8 def self.runtime Thread.current['sequel_sql_runtime'] ||= 0 end |
.runtime=(value) ⇒ Object
4 5 6 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 4 def self.runtime=(value) Thread.current['sequel_sql_runtime'] = value end |
Instance Method Details
#logger ⇒ Object
57 58 59 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 57 def logger ::SequelRails.configuration.logger end |
#odd? ⇒ Boolean
53 54 55 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 53 def odd? @odd_or_even = !@odd_or_even end |
#sql(event) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sequel_rails/railties/log_subscriber.rb', line 32 def sql(event) self.class.runtime += event.duration self.class.count += 1 return unless logger.debug? payload = event.payload name = format('%s (%.1fms)', payload[:name], event.duration) sql = payload[:sql].squeeze(' ') binds = " #{payload[:binds].inspect}" unless (payload[:binds] || []).empty? if odd? name = color(name, :cyan, :bold => true) sql = color(sql, nil, :bold => true) else name = color(name, :magenta, :bold => true) end debug " #{name} #{sql}#{binds}" end |