Class: Superlogger::ActiveRecordLogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Superlogger::ActiveRecordLogSubscriber
- Defined in:
- lib/superlogger/active_record_log_subscriber.rb
Constant Summary collapse
- IGNORE_PAYLOAD_NAMES =
["SCHEMA", "EXPLAIN", "ActiveRecord::SchemaMigration Load"]
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.runtime ⇒ Object
9 10 11 |
# File 'lib/superlogger/active_record_log_subscriber.rb', line 9 def self.runtime ActiveRecord::RuntimeRegistry.sql_runtime ||= 0 end |
.runtime=(value) ⇒ Object
5 6 7 |
# File 'lib/superlogger/active_record_log_subscriber.rb', line 5 def self.runtime=(value) ActiveRecord::RuntimeRegistry.sql_runtime = value end |
Instance Method Details
#sql(event) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/superlogger/active_record_log_subscriber.rb', line 13 def sql(event) self.class.runtime += event.duration return if Rails.env.production? payload = event.payload return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) logger.debug do sql = payload[:sql] params = payload[:binds].map { |b| b.value.to_s } { sql: sql, params: params, duration: event.duration.round(2) } end end |