Sha256: 24e61dfacda5d7fa504d96c5eee1ff99381788f5fc5435c5a35b6b1dc65f0f7e

Contents?: true

Size: 585 Bytes

Versions: 2

Compression:

Stored size: 585 Bytes

Contents

# frozen_string_literal: true

module Lograge
  # Log subscriber to replace ActiveRecord's default one
  class ActiveRecordLogSubscriber < ActiveSupport::LogSubscriber
    # Every time there's an SQL query, stores it into the Thread.
    # They'll later be access from the RequestLogSubscriber.
    def sql(event)
      ActiveRecord::LogSubscriber.runtime += event.duration
      return if event.payload[:name] == 'SCHEMA'

      Lograge::Sql.store[:lograge_sql_queries] ||= []
      Lograge::Sql.store[:lograge_sql_queries] << Lograge::Sql.extract_event.call(event)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lograge-sql-2.0.0 lib/lograge/active_record_log_subscriber.rb
lograge-sql-1.3.1 lib/lograge/active_record_log_subscriber.rb