Sha256: 7f326fca196cbeee0e3a79acef6d31a0ce325dfc45fb3c1dfd9d422afc8079f8

Contents?: true

Size: 964 Bytes

Versions: 10

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true

require 'lograge/active_record_log_subscriber'

module Lograge
  module Sql
    # Module used to extend Lograge
    module Extension
      # Overrides `Lograge::RequestLogSubscriber#extract_request` do add SQL queries
      def extract_request(event, payload)
        super.merge!(extract_sql_queries)
      end

      # Collects all SQL queries stored in the Thread during request processing
      def extract_sql_queries
        sql_queries = Lograge::Sql.store[:lograge_sql_queries]
        return {} unless sql_queries

        Lograge::Sql.store[:lograge_sql_queries] = nil
        {
          sql_queries: Lograge::Sql.formatter.call(sql_queries),
          sql_queries_count: sql_queries.length
        }
      end
    end
  end
end

if defined?(Lograge::RequestLogSubscriber)
  Lograge::RequestLogSubscriber.prepend Lograge::Sql::Extension
else
  Lograge::LogSubscribers::ActionController.prepend Lograge::Sql::Extension
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lograge-sql-2.5.1 lib/lograge/sql/extension.rb
lograge-sql-2.5.0 lib/lograge/sql/extension.rb
lograge-sql-2.4.0 lib/lograge/sql/extension.rb
lograge-sql-2.3.2 lib/lograge/sql/extension.rb
lograge-sql-2.3.1 lib/lograge/sql/extension.rb
lograge-sql-2.3.0 lib/lograge/sql/extension.rb
lograge-sql-2.2.0 lib/lograge/sql/extension.rb
lograge-sql-2.1.0 lib/lograge/sql/extension.rb
lograge-sql-2.0.0 lib/lograge/sql/extension.rb
lograge-sql-1.3.1 lib/lograge/sql/extension.rb