Sha256: 1406dd67c47d9d43e9af1b330f6b5d87a44576844038bc0dce05ebb77585bf5e

Contents?: true

Size: 741 Bytes

Versions: 34

Compression:

Stored size: 741 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

      def odd?
        @odd_or_even = !@odd_or_even
      end
    end
  end
end

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

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
rom-sql-1.2.1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.2.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.1.2 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.1.1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.1.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.3 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.2 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.0.rc2 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.0.rc1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.0.beta3 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.0.beta2 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-1.0.0.beta1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-0.9.1 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-0.9.0 lib/rom/sql/extensions/rails_log_subscriber.rb
rom-sql-0.8.0 lib/rom/sql/support/rails_log_subscriber.rb
rom-sql-0.7.0 lib/rom/sql/support/rails_log_subscriber.rb
rom-sql-0.7.0.rc1 lib/rom/sql/support/rails_log_subscriber.rb
rom-sql-0.7.0.beta1 lib/rom/sql/support/rails_log_subscriber.rb