-
-
Save stympy/1101641 to your computer and use it in GitHub Desktop.
Let Rails display file names and line numbers for log activity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
module ConnectionAdapters | |
class AbstractAdapter | |
protected | |
# Turn: | |
# User Load (6.3ms) SELECT * FROM "users" | |
# Into: | |
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users" | |
# Rails 3.0 | |
def log_with_trace(sql, name = "SQL", &block) | |
@stringified_rails_root ||= Rails.root.to_s | |
if @logger && @logger.debug? | |
c = caller.detect{|line| line !~ /(activerecord|active_support|__DELEGATION__|\/lib\/|\/vendor\/plugins|\/vendor\/gems)/i} | |
c ||= caller.first | |
c.gsub! @stringified_rails_root, '' | |
name = "#{name} #{c}" | |
end | |
log_without_trace sql, name, &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