Class: ActiveRecordProfiler::Logger

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/active-record-profiler/logger.rb

Instance Method Summary collapse

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active-record-profiler/logger.rb', line 6

def add(severity, message = nil, progname = nil, &block)
  return true if (severity || ::Logger::Severity::UNKNOWN) < self.level
  start_time = Time.now.to_f

  called_block = false
  if message.nil?
    if block_given?
      message = yield
      called_block = true
    else
      message = progname
      progname = self.progname
    end
  end

  message = add_call_site_to_message(message)
  collector.record_self_info((Time.now.to_f - start_time), 'enhancing log line') if ActiveRecordProfiler::Collector.profile_self?

  # We don't use super() here to pass control to the delegate because if we 
  # do, there's no way to prevent super() from seeing the block and yielding
  # to it, and if we've already yielded to the block, this could result in a
  # double yield (if the message is nil after calling the block).
  if called_block
    # don't pass the block, since we already called it
    __getobj__.add(severity, message, progname)
  else  
    __getobj__.add(severity, message, progname, &block)
  end
end