Sha256: 19ff20021387215a637c0cf93b8dc423f80a09d313b9f441efb54f376afdcbcf

Contents?: true

Size: 1.08 KB

Versions: 37

Compression:

Stored size: 1.08 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 #{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

37 entries across 37 versions & 1 rubygems

Version Path
switchman-1.2.35 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.34 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.33 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.32 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.31 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.30 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.29 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.28 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.27 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.26 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.25 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.24 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.23 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.22 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.21 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.20 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.19 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.18 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.17 lib/switchman/active_record/log_subscriber.rb
switchman-1.2.16 lib/switchman/active_record/log_subscriber.rb