Rails Task 的便捷调试


最近为Rails程序加了不少Task,为方便调试采用如下方法。 1、在task目录增加debug.rake文件,文件内容如下。

desc "switch rails logger to stdout"
task :verbose => [:environment] do
Rails.logger = Logger.new(STDOUT)
end

desc "switch rails logger log level to debug"
task :debug => [:environment, :verbose] do
Rails.logger.level = Logger::DEBUG
end

desc "switch rails logger log level to info"
task :info => [:environment, :verbose] do
Rails.logger.level = Logger::INFO
end

2、这样就可以直接跑现有task的debug模式了。

rails debug taskname:something
comments powered by Disqus