diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2018-08-15 20:16:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-15 20:16:43 +0200 |
commit | 977d77e9e250a323f64785042d9ad8412368c19a (patch) | |
tree | 8f0e67b907628ed40fc683e8c4bad473ce8a32df /activerecord | |
parent | efaa7191f24da079e785b00019a9ef252f841a8c (diff) | |
parent | c675783eb4fb42a357ec068d4cfd83bf08f78aea (diff) | |
download | rails-977d77e9e250a323f64785042d9ad8412368c19a.tar.gz rails-977d77e9e250a323f64785042d9ad8412368c19a.tar.bz2 rails-977d77e9e250a323f64785042d9ad8412368c19a.zip |
Merge pull request #33499 from lsylvester/caller-ignore-paths
use BacktraceCleaner for ActiveRecord verbose logging
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 14 | ||||
-rw-r--r-- | activerecord/lib/active_record/railtie.rb | 4 |
2 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 1ae6840921..6b84431343 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -4,6 +4,8 @@ module ActiveRecord class LogSubscriber < ActiveSupport::LogSubscriber IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"] + class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new + def self.runtime=(value) ActiveRecord::RuntimeRegistry.sql_runtime = value end @@ -100,21 +102,15 @@ module ActiveRecord end def log_query_source - location = extract_query_source_location(caller_locations) - - if location - source = "#{location.path}:#{location.lineno}" - source = source.sub("#{::Rails.root}/", "") if defined?(::Rails.root) + source = extract_query_source_location(caller) + if source logger.debug(" ↳ #{source}") end end - RAILS_GEM_ROOT = File.expand_path("../../..", __dir__) + "/" - PATHS_TO_IGNORE = /\A(#{RAILS_GEM_ROOT}|#{RbConfig::CONFIG["rubylibdir"]})/ - def extract_query_source_location(locations) - locations.find { |line| line.absolute_path && !line.absolute_path.match?(PATHS_TO_IGNORE) } + backtrace_cleaner.clean(locations).first end end end diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 009f412234..7ece083fd4 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -77,6 +77,10 @@ module ActiveRecord ActiveSupport.on_load(:active_record) { self.logger ||= ::Rails.logger } end + initializer "active_record.backtrace_cleaner" do + ActiveSupport.on_load(:active_record) { LogSubscriber.backtrace_cleaner = ::Rails.backtrace_cleaner } + end + initializer "active_record.migration_error" do if config.active_record.delete(:migration_error) == :page_load config.app_middleware.insert_after ::ActionDispatch::Callbacks, |