Class: Lograge::ActiveRecordLogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Lograge::ActiveRecordLogSubscriber
- Defined in:
- lib/lograge/active_record_log_subscriber.rb
Overview
Log subscriber to replace ActiveRecord’s default one
Instance Method Summary collapse
-
#sql(event) ⇒ Object
Every time there’s an SQL query, stores it into the Thread.
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.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lograge/active_record_log_subscriber.rb', line 8 def sql(event) increase_runtime_duration(event) return if event.payload[:name] == 'SCHEMA' # Only store SQL events if `event.duration` is greater than the configured +min_duration+ # No need to check if +min_duration+ is present before as it defaults to 0 return if event.duration.to_f.round(2) < Lograge::Sql.min_duration_ms.to_f Lograge::Sql.store[:lograge_sql_queries] ||= [] Lograge::Sql.store[:lograge_sql_queries] << Lograge::Sql.extract_event.call(event) end |