Module: Switchman::ActiveRecord::LogSubscriber

Defined in:
lib/switchman/active_record/log_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
# File 'lib/switchman/active_record/log_subscriber.rb', line 4

def self.included(klass)
  klass.send(:remove_method, :sql)
end

Instance Method Details

#sql(event) ⇒ Object

sadly, have to completely replace this



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/switchman/active_record/log_subscriber.rb', line 9

def sql(event)
  self.class.runtime += event.duration
  return unless logger.debug?

  payload = event.payload

  return if 'SCHEMA' == payload[:name]

  name  = '%s (%.1fms)' % [payload[:name], event.duration]
  sql   = payload[:sql].squeeze(' ')
  binds = nil
  shard = payload[:shard]
  shard = "  [shard #{shard[:id]} #{shard[:env]}]" if shard

  unless (payload[:binds] || []).empty?
    binds = "  " + payload[:binds].map { |col,v|
      if col
        [col.name, v]
      else
        [nil, v]
      end
    }.inspect
  end

  if odd?
    name = color(name, self.class::CYAN, true)
    sql  = color(sql, nil, true)
  else
    name = color(name, self.class::MAGENTA, true)
  end

  debug "  #{name}  #{sql}#{binds}#{shard}"
end