Sha256: 3f1b305dae22e493a8f048548cf71de5f6a8a0e7b1932698b26223b33bc4308e
Contents?: true
Size: 796 Bytes
Versions: 2
Compression:
Stored size: 796 Bytes
Contents
module Superlogger class ActiveRecordLogSubscriber < ActiveSupport::LogSubscriber IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN", "ActiveRecord::SchemaMigration Load"] def self.runtime=(value) ActiveRecord::RuntimeRegistry.sql_runtime = value end def self.runtime ActiveRecord::RuntimeRegistry.sql_runtime ||= 0 end def sql(event) self.class.runtime += event.duration return if Rails.env.production? payload = event.payload return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) sql = payload[:sql] params = payload[:binds].map { |_, value| "'#{value}'"} Logger.debug sql: sql, params: params, duration: event.duration.round(2) end end end Superlogger::ActiveRecordLogSubscriber.attach_to :active_record
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
superlogger-0.0.2 | lib/superlogger/active_record_log_subscriber.rb |
superlogger-0.0.1 | lib/superlogger/active_record_log_subscriber.rb |