aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/log_subscriber.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/log_subscriber.rb')
-rw-r--r--activerecord/lib/active_record/log_subscriber.rb33
1 files changed, 9 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb
index cf884bc6da..1ae6840921 100644
--- a/activerecord/lib/active_record/log_subscriber.rb
+++ b/activerecord/lib/active_record/log_subscriber.rb
@@ -100,36 +100,21 @@ module ActiveRecord
end
def log_query_source
- source_line, line_number = extract_callstack(caller_locations)
+ location = extract_query_source_location(caller_locations)
- if source_line
- if defined?(::Rails.root)
- app_root = "#{::Rails.root}/"
- source_line = source_line.sub(app_root, "")
- end
+ if location
+ source = "#{location.path}:#{location.lineno}"
+ source = source.sub("#{::Rails.root}/", "") if defined?(::Rails.root)
- logger.debug(" ↳ #{ source_line }:#{ line_number }")
+ logger.debug(" ↳ #{source}")
end
end
- def extract_callstack(callstack)
- line = callstack.find do |frame|
- frame.absolute_path && !ignored_callstack(frame.absolute_path)
- end
-
- offending_line = line || callstack.first
-
- [
- offending_line.path,
- offending_line.lineno
- ]
- end
-
- RAILS_GEM_ROOT = File.expand_path("../../..", __dir__) + "/"
+ RAILS_GEM_ROOT = File.expand_path("../../..", __dir__) + "/"
+ PATHS_TO_IGNORE = /\A(#{RAILS_GEM_ROOT}|#{RbConfig::CONFIG["rubylibdir"]})/
- def ignored_callstack(path)
- path.start_with?(RAILS_GEM_ROOT) ||
- path.start_with?(RbConfig::CONFIG["rubylibdir"])
+ def extract_query_source_location(locations)
+ locations.find { |line| line.absolute_path && !line.absolute_path.match?(PATHS_TO_IGNORE) }
end
end
end