Sha256: 5b5fbdd219ad7ece1ec79457082b2985c639e6806609fa3cc0094fa15d3343b3

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

module SequelRails
  module Railties

    class LogSubscriber < ActiveSupport::LogSubscriber

      def self.runtime=(value)
        Thread.current["sequel_sql_runtime"] = value
      end

      def self.runtime
        Thread.current["sequel_sql_runtime"] ||= 0
      end

      def self.reset_runtime
        rt, self.runtime = runtime, 0
        rt
      end

      def sql(event)
        self.class.runtime += event.duration
        return unless logger.debug?

        payload = event.payload

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

        unless (payload[:binds] || []).empty?
          binds = "  " + payload[:binds].map { |col,v|
            [col.name, v]
          }.inspect
        end

        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

      def logger
        ::SequelRails.configuration.logger
      end

    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sequel-rails-0.7.0 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.6.1 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.6.0 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.5.1 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.5.0 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.4 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.3 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.2 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.1 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.0 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.0.pre2 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.0.pre1 lib/sequel_rails/railties/log_subscriber.rb
sequel-rails-0.4.0.pre lib/sequel_rails/railties/log_subscriber.rb