class Epilog::Rails::ActiveRecordSubscriber
Constants
- IGNORE_PAYLOAD_NAMES
Public Instance Methods
sql(event)
click to toggle source
# File lib/epilog/rails/active_record_subscriber.rb, line 8 def sql(event) ActiveRecord::LogSubscriber.runtime += event.duration return unless logger.debug? payload = event.payload return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) debug( message: payload[:name], sql: payload[:sql], binds: binds_info(payload[:binds] || []), metrics: metrics(event) ) end
Private Instance Methods
bind_attr_info(attr)
click to toggle source
# File lib/epilog/rails/active_record_subscriber.rb, line 52 def bind_attr_info(attr) info = { type: attr.type.type, name: attr.name } if attr.type.binary? && attr.value info[:bytes] = attr.value_for_database.to_s.bytesize else info[:value] = attr.value_for_database end info end
bind_column_info(column, value)
click to toggle source
# File lib/epilog/rails/active_record_subscriber.rb, line 42 def bind_column_info(column, value) info = { type: column.type, name: column.name } if column.binary? info[:bytes] = value.bytesize else info[:value] = value end info end
binds_info(binds)
click to toggle source
# File lib/epilog/rails/active_record_subscriber.rb, line 32 def binds_info(binds) binds.map do |bind| if bind.is_a?(Array) bind_column_info(*bind) else bind_attr_info(bind) end end end
metrics(event)
click to toggle source
# File lib/epilog/rails/active_record_subscriber.rb, line 26 def metrics(event) { query_runtime: event.duration.round(2) } end