Sha256: 89529d22e347f53c4f6a9edaa08c21521b33e50d4e356929a9ad901563d5f7e5

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 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'.freeze == payload[:name]

        name  = '%s (%.1fms)'.freeze % [payload[:name], event.duration]
        sql   = payload[:sql].squeeze(' '.freeze)
        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

7 entries across 7 versions & 1 rubygems

Version Path
switchman-1.4.3 lib/switchman/active_record/log_subscriber.rb
switchman-1.4.2 lib/switchman/active_record/log_subscriber.rb
switchman-1.4.1 lib/switchman/active_record/log_subscriber.rb
switchman-1.4.0 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.18 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.17 lib/switchman/active_record/log_subscriber.rb
switchman-1.3.16 lib/switchman/active_record/log_subscriber.rb