aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2018-08-15 20:16:43 +0200
committerGitHub <noreply@github.com>2018-08-15 20:16:43 +0200
commit977d77e9e250a323f64785042d9ad8412368c19a (patch)
tree8f0e67b907628ed40fc683e8c4bad473ce8a32df /activesupport/lib/active_support
parentefaa7191f24da079e785b00019a9ef252f841a8c (diff)
parentc675783eb4fb42a357ec068d4cfd83bf08f78aea (diff)
downloadrails-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 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/backtrace_cleaner.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/backtrace_cleaner.rb b/activesupport/lib/active_support/backtrace_cleaner.rb
index 16dd733ddb..1796956bd7 100644
--- a/activesupport/lib/active_support/backtrace_cleaner.rb
+++ b/activesupport/lib/active_support/backtrace_cleaner.rb
@@ -31,6 +31,9 @@ module ActiveSupport
class BacktraceCleaner
def initialize
@filters, @silencers = [], []
+ add_gem_filter
+ add_gem_silencer
+ add_stdlib_silencer
end
# Returns the backtrace after all filters and silencers have been run
@@ -82,6 +85,26 @@ module ActiveSupport
end
private
+
+ FORMATTED_GEMS_PATTERN = /\A[^\/]+ \([\w.]+\) /
+
+ def add_gem_filter
+ gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
+ return if gems_paths.empty?
+
+ gems_regexp = %r{(#{gems_paths.join('|')})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)}
+ gems_result = '\3 (\4) \5'.freeze
+ add_filter { |line| line.sub(gems_regexp, gems_result) }
+ end
+
+ def add_gem_silencer
+ add_silencer { |line| FORMATTED_GEMS_PATTERN.match?(line) }
+ end
+
+ def add_stdlib_silencer
+ add_silencer { |line| line.start_with?(RbConfig::CONFIG["rubylibdir"]) }
+ end
+
def filter_backtrace(backtrace)
@filters.each do |f|
backtrace = backtrace.map { |line| f.call(line) }