Sha256: e5469e8cdaf4835f9c6c5e4b11aeb7a6a5e2874e6174eb8a753236a2232d7d88

Contents?: true

Size: 798 Bytes

Versions: 21

Compression:

Stored size: 798 Bytes

Contents

require 'active_support/log_subscriber'

module ROM
  module SQL
    class RailsLogSubscriber < ActiveSupport::LogSubscriber
      def sql(event)
        return unless logger.debug?

        payload = event.payload

        name = format('%s (%.1fms)', payload[:name], event.duration)
        sql  = payload[:sql].squeeze(' ')
        binds = payload[:binds].to_a.inspect if payload[:binds]

        if odd?
          name = color(name, :cyan, true)
          sql  = color(sql, nil, true)
        else
          name = color(name, :magenta, true)
        end

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

      attr_reader :odd_or_even
      private :odd_or_even
      def odd?
        @odd_or_even = !odd_or_even
      end
    end
  end
end

ROM::SQL::RailsLogSubscriber.attach_to(:rom)

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rom-sql-3.1.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-3.0.1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-3.0.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.5.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.4.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.3.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.2.1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.2.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.1.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.0.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.3.5 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.0.0.rc1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.3.4 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.0.0.beta3 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.0.0.beta2 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-2.0.0.beta1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.3.3 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.3.2 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.3.1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.3.0 lib/rom/sql/extensions/rails_log_subscriber.rb