Sha256: ab559ed2a4f2b05d60349b08f9b86aec4716d588ca1809bb1bbc10f2850df3fa

Contents?: true

Size: 963 Bytes

Versions: 3

Compression:

Stored size: 963 Bytes

Contents

ActiveRecord::LogSubscriber
module ActiveRecord
  class LogSubscriber
    def sql(event)
      self.class.runtime += event.duration

      return unless logger.debug?

      payload = event.payload
      name    = payload[:name]
      return if IGNORE_PAYLOAD_NAMES.include?(name)

      log_payload = {
        sql:      payload[:sql],
      }
      log = {
        message:  name,
        payload:  log_payload,
        duration: event.duration
      }
      unless (payload[:binds] || []).empty?
        log_payload[:binds] = binds = {}
        # Changed with Rails 5
        if Rails.version.to_i >= 5
          payload[:binds].each do |attr|
            attr_name, value = render_bind(attr)
            binds[attr_name] = value
          end
        else
          payload[:binds].each do |col, v|
            attr_name, value = render_bind(col, v)
            binds[attr_name] = value
          end
        end
      end
      debug(log)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_semantic_logger-4.0.0 lib/rails_semantic_logger/extensions/active_record/log_subscriber.rb
rails_semantic_logger-4.0.0.rc1 lib/rails_semantic_logger/extensions/active_record/log_subscriber.rb
rails_semantic_logger-4.0.0.beta2 lib/rails_semantic_logger/extensions/active_record/log_subscriber.rb