Class: Lograge::ActiveRecordLogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/lograge/sql/extension.rb

Overview

Log subscriber to replace ActiveRecord’s default one

Instance Method Summary collapse

Instance Method Details

#sql(event) ⇒ Object

Every time there’s an SQL query, stores it into the Thread. They’ll later be access from the RequestLogSubscriber.



32
33
34
35
36
37
38
# File 'lib/lograge/sql/extension.rb', line 32

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