Class: Lograge::ActiveRecordLogSubscriber

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

Instance Method Summary collapse

Instance Method Details

#sql(event) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/lograge/sql/extension.rb', line 24

def sql(event)
  ActiveRecord::LogSubscriber.runtime += event.duration
  return if event.payload[:name] == 'SCHEMA'
  Thread.current[:lograge_sql_queries] ||= []
  Thread.current[:lograge_sql_queries] << ("\n[#{event.transaction_id}] #{event.payload[:name]} (#{event.duration.to_f.round(2)}) #{event.payload[:sql]}")

  Thread.current[:transaction_id] ||= event.transaction_id
end