如何从rails中的应用程序中仅获取堆栈跟踪?

时间:2010-04-17 00:28:38

标签: ruby-on-rails exception-handling

默认行为似乎是打印大堆栈跟踪,如

ArgumentError (too few arguments):
app/controllers/players_controller.rb:55:in `format'
app/controllers/players_controller.rb:55:in `create'
/dh/passenger/lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
/dh/passenger/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:400:in `start_request_handler'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:351:in `handle_spawn_application'
/dh/passenger/lib/phusion_passenger/utils.rb:184:in `safe_fork'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:349:in `handle_spawn_application'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:163:in `start'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:209:in `start'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
/dh/passenger/lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
/dh/passenger/lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
/dh/passenger/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'

但我只想从我的应用程序中看到堆栈跟踪。在这种情况下,它是前3行,包括实际的错误,然后是我的应用程序的部分。在这种情况下,我更愿意看到这一点:

ArgumentError (too few arguments):
app/controllers/players_controller.rb:55:in `format'
app/controllers/players_controller.rb:55:in `create'

这可能吗?

1 个答案:

答案 0 :(得分:1)

如果您使用Rails> = 2.3,答案是回溯消音器 http://afreshcup.com/home/2008/11/29/rails-23-backtrace-silencing.html

来自release notes

  

Rails会自动添加消音器   摆脱一个最常见的噪音   新的应用程序,并构建一个   config / backtrace_silencers.rb文件到   保留你自己的补充

如果您使用的是早期版本的Rails,请使用http://github.com/thoughtbot/quietbacktrace