Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save assembler/1442310 to your computer and use it in GitHub Desktop.
Save assembler/1442310 to your computer and use it in GitHub Desktop.
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Rails 3.1
def log_with_trace(sql, name = "SQL", binds = [], &block)
if @logger && @logger.debug?
c = caller.detect{|line| line !~ /(activerecord|active_support|__DELEGATION__|\/lib\/|\/vendor\/plugins|\/vendor\/gems)/i}
c ||= caller.first
c.gsub!("#{File.expand_path(File.dirname(Rails.root))}/", '') if defined?(Rails)
name = "#{name} #{c}"
end
log_without_trace sql, name, binds, &block
end
alias_method_chain :log, :trace
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment