class LogStasher::ActiveRecord::LogSubscriber

Public Instance Methods

identity(event) click to toggle source
# File lib/logstasher/active_record/log_subscriber.rb, line 12
def identity(event)
  lsevent = logstash_event(event)
  logger << "#{lsevent.to_json}\n" if logger && lsevent
end
Also aliased as: sql
logger() click to toggle source
# File lib/logstasher/active_record/log_subscriber.rb, line 18
def logger
  LogStasher.logger
end
sql(event)
Alias for: identity

Private Instance Methods

extract_sql(data) click to toggle source
# File lib/logstasher/active_record/log_subscriber.rb, line 57
def extract_sql(data)
  { sql: data[:sql].squeeze(' ') }
end
logstash_event(event) click to toggle source
# File lib/logstasher/active_record/log_subscriber.rb, line 24
def logstash_event(event)
  self.class.runtime += event.duration
  data = event.payload.dup

  return if data[:name] == 'SCHEMA'

  # A connection cannot be converted to JSON as it fails with
  # SystemStackError when running against ActiveSupport JSON patches.
  data.delete(:connection)

  data.merge! runtimes(event)
  data.merge! extract_sql(data)
  data.merge! request_context
  data.merge! LogStasher.store
  data.merge! extract_custom_fields(data)

  tags = ['request']
  tags.push('exception') if data[:exception]
  LogStasher.build_logstash_event(data, tags)
end
request_context() click to toggle source
# File lib/logstasher/active_record/log_subscriber.rb, line 45
def request_context
  LogStasher.request_context
end
runtimes(event) click to toggle source
# File lib/logstasher/active_record/log_subscriber.rb, line 49
def runtimes(event)
  if event.duration
    { duration: event.duration.to_f.round(2) }
  else
    {}
  end
end