Class: QueryTracer::Logger

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/query_tracer/logger.rb

Instance Method Summary collapse

Instance Method Details

#sql(event) ⇒ Object

event.payload event.duration event.payload



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/query_tracer/logger.rb', line 10

def sql(event)
  return unless QueryTracer.config.enabled
  
  sql = event.payload[:sql]
  # Skip noisy queries
  trace = Tracer.build_trace(sql)
  unless trace.blank?
    message = color("^^^^ Called from: ", YELLOW, true)
    indent  = color("-> ", YELLOW, true)

    send QueryTracer.config.log_level, message + trace.join("\n#{indent}")
  end
end