diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-22 18:06:08 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-22 18:06:08 +0100 |
commit | f42c77f927eb49b00e84d355e07de48723d03fcb (patch) | |
tree | 2a459814a9708f292c99e9c5e99dd41d2d801353 /railties | |
parent | a026b4c983681b71d876ea37958c3e5bc605acac (diff) | |
download | rails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.gz rails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.bz2 rails-f42c77f927eb49b00e84d355e07de48723d03fcb.zip |
Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) [DHH]
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/Rakefile | 6 | ||||
-rw-r--r-- | railties/configs/initializers/backtrace_silencers.rb | 7 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/backtrace_cleaner.rb | 34 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/app_generator.rb | 7 |
6 files changed, 59 insertions, 5 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index a93052298b..6a644ca63a 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *2.3.0 [Edge]* +* Added Rails.backtrace_cleaner as an accessor for the Rails::BacktraceCleaner instance used by the framework to cut down on backtrace noise and config/initializers/backtrace_silencers.rb to add your own (or turn them all off) [DHH] + * Switch from Test::Unit::TestCase to ActiveSupport::TestCase. [Jeremy Kemper] * Added config.i18n settings gatherer to config/environment, auto-loading of all locales in config/locales/*.rb,yml, and config/locales/en.yml as a sample locale [DHH] diff --git a/railties/Rakefile b/railties/Rakefile index 8c8bec0d27..cbfa14e887 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -197,8 +197,10 @@ task :copy_configs do cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb" - cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb" - cp "configs/initializers/mime_types.rb", "#{PKG_DESTINATION}/config/initializers/mime_types.rb" + cp "configs/initializers/backtrace_silencers.rb", "#{PKG_DESTINATION}/config/initializers/backtrace_silencers.rb" + cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb" + cp "configs/initializers/mime_types.rb", "#{PKG_DESTINATION}/config/initializers/mime_types.rb" + cp "configs/initializers/new_rails_defaults.rb", "#{PKG_DESTINATION}/config/initializers/new_rails_defaults.rb" cp "configs/locales/en.yml", "#{PKG_DESTINATION}/config/locales/en.yml" diff --git a/railties/configs/initializers/backtrace_silencers.rb b/railties/configs/initializers/backtrace_silencers.rb new file mode 100644 index 0000000000..c2169ed01c --- /dev/null +++ b/railties/configs/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code. +# Rails.backtrace_cleaner.remove_silencers!
\ No newline at end of file diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 16abe62d1b..fcf6ea3feb 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -39,6 +39,14 @@ module Rails nil end end + + def backtrace_cleaner + @@backtrace_cleaner ||= begin + # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded + require 'rails/backtrace_cleaner' + Rails::BacktraceCleaner.new + end + end def root if defined?(RAILS_ROOT) diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb new file mode 100644 index 0000000000..ffc5ef42aa --- /dev/null +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -0,0 +1,34 @@ +module Rails + class BacktraceCleaner < ActiveSupport::BacktraceCleaner + ERB_METHOD_SIG = /:in `_run_erb_.*/ + + VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) + MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) + RAILS_NOISE = %w( script/server ) + RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) + + ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE + + + def initialize + super + add_filter { |line| line.sub(RAILS_ROOT, '') } + add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + end + end + + + # For installing the BacktraceCleaner in the test/unit + module BacktraceFilterForTestUnit #:nodoc: + def self.included(klass) + klass.send :alias_method_chain, :filter_backtrace, :cleaning + end + + def filter_backtrace_with_cleaning(backtrace) + backtrace = filter_backtrace_without_cleaning(backtrace) + backtrace = backtrace.first.split("\n") if backtrace.size == 1 + Rails.backtrace_cleaner.clean(backtrace) + end + end +end
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 347ce6352c..e52dcadd4d 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -62,9 +62,10 @@ class AppGenerator < Rails::Generator::Base m.template "configs/routes.rb", "config/routes.rb" # Initializers - m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" - m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" - m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" + m.template "configs/initializers/backtrace_silencers.rb", "config/initializers/backtrace_silencers.rb" + m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" + m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" + m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" # Locale m.template "configs/locales/en.yml", "config/locales/en.yml" |