Sha256: a6df427208ec95883113b00e47404843c191869040a7d668e41d39b016ff19c3

Contents?: true

Size: 1.11 KB

Versions: 24

Compression:

Stored size: 1.11 KB

Contents

module Switchman
  module ActiveRecord
    module LogSubscriber
      def self.included(klass)
        klass.send(:remove_method, :sql)
      end

      # sadly, have to completely replace this
      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[:database_server_id]}:#{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
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
switchman-1.3.14.pre.1 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.13.pre.1 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.15 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.14 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.13 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.12 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.11 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.10 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.9 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.8 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.7 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.6 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.5 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.4 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.3 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.2 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.1 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.0 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.41 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.40 lib/switchman/active_record/log_subscriber.rb