开发者

Rake: logging any task executing

开发者 https://www.devze.com 2023-03-08 23:26 出处:网络
how can I createdatabase logging for every rake taskwithout changing source of tasks ? I need to store datetime , task nam开发者_C百科e , parameters . Is there some kind of observer etc ?You can overr

how can I create database logging for every rake task without changing source of tasks ? I need to store datetime , task nam开发者_C百科e , parameters . Is there some kind of observer etc ?


You can override Rake::Task#invoke method in application.rb:

#application.rb
module Rake
  class Task
    alias_method :origin_invoke, :invoke if method_defined?(:invoke)
    def invoke(*args)
      logger = Logger.new('rake_tasks_log.log')
      logger.info "#{Time.now} -- #{name} -- #{args.inspect}"
      origin_invoke(*args)
    end
  end
end

output for rake test:

2011-05-27 16:57:42 +0300 -- test -- []
2011-05-27 16:57:42 +0300 -- test:units -- []
2011-05-27 16:57:51 +0300 -- db:test:load -- []
2011-05-27 16:57:51 +0300 -- db:schema:load -- []
2011-05-27 16:58:19 +0300 -- test:functionals -- []
2011-05-27 16:58:49 +0300 -- test:integration -- []
0

精彩评论

暂无评论...
验证码 换一张
取 消