class ActiveRecordProfiler::Logger
Public Instance Methods
add(severity, message = nil, progname = nil) { || ... }
click to toggle source
# 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
Protected Instance Methods
add_call_site_to_message(msg)
click to toggle source
# File lib/active-record-profiler/logger.rb, line 52 def add_call_site_to_message(msg) message = msg if String === msg match = /^\s*(?:\e\[\d+m)*(:?[^(]*)\(([0-9.]+)\s*([a-z]s(:?econds)?)\)(?:\e\[\d+m)*\s*(.*)/.match(msg) if match loc = collector.call_location_name message = "#{msg} CALLED BY '#{formatted_location(loc)}'" end end return message end
collector()
click to toggle source
# File lib/active-record-profiler/logger.rb, line 67 def collector ActiveRecordProfiler::Collector.instance end
formatted_location(loc)
click to toggle source
# File lib/active-record-profiler/logger.rb, line 71 def formatted_location(loc) if Rails.configuration.colorize_logging "\e[4;32;1m#{loc}\e[0m" else loc end end