Sha256: aa9856b97dee843d6e1084887d3a1a4a3897e0ae40a605c8dfdb6dbec597a3a4

Contents?: true

Size: 1.47 KB

Versions: 34

Compression:

Stored size: 1.47 KB

Contents

# We require all of ActiveRecord because the #logger method in ::ActiveRecord::LogSubscriber
# uses ActiveRecord::Base. We can't require active_record/base directly because ActiveRecord
# does not require files properly and we receive unintialized constant errors.
require "active_record"
require "active_record/log_subscriber"

require "timber/integrator"

module Timber
  module Integrations
    module ActiveRecord
      class LogSubscriber < Integrator
        # The log subscriber that replaces the default `ActiveRecord::LogSubscriber`.
        # The intent of this subscriber is to, as transparently as possible, properly
        # track events that are being logged here. This LogSubscriber will never change
        # default behavior / log messages.
        #
        # @private
        class TimberLogSubscriber < ::ActiveRecord::LogSubscriber
          def sql(event)
            return true if silence?

            r = super(event)

            if @message
              payload = event.payload
              event = Events::SQLQuery.new(
                sql: payload[:sql],
                time_ms: event.duration,
                message: @message
              )

              logger.debug event

              @message = nil
            end

            r
          end

          private
            def debug(message)
              @message = message
            end

            def silence?
              ActiveRecord.silence?
            end
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
timber-2.6.2 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.6.1 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.6.0 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.6.0.pre.beta2 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.6.0.pre.beta1 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.5.1 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.5.0 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.4.0 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.3.4 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.3.3 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.3.2 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.3.1 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.3.0 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.2.3 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.2.2 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.2.1 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.2.0 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.1.10 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.1.9 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb
timber-2.1.8 lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb