Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.81 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. module ActiveRecord
  2.   module ConnectionAdapters
  3.     class AbstractAdapter
  4.       protected
  5.  
  6.         # Turn:
  7.         # User Load (6.3ms)  SELECT * FROM "users"
  8.         # Into:
  9.         # User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb`  SELECT * FROM "users"
  10.  
  11.         # Rails 3.0
  12.         def log_with_trace(sql, name = "SQL", &block)
  13.           @stringified_rails_root ||= Rails.root.to_s
  14.           if @logger && @logger.debug?
  15.             c = caller.detect{|line| line !~ /(activerecord|active_support|__DELEGATION__|\/lib\/|\/vendor\/plugins|\/vendor\/gems)/i}
  16.             c ||= caller.first
  17.             c.gsub! @stringified_rails_root, ''
  18.             name = "#{name} #{c}"
  19.           end
  20.           log_without_trace sql, name, &block
  21.         end
  22.  
  23.         alias_method_chain :log, :trace
  24.     end
  25.   end
  26. end