2014-02-20 33 views
0

我希望能夠從SSHKit調用的rake任務輸出信息,但我看不到如何去做。從SSHKit調用的rake任務顯示輸出

說我有以下的rake任務:

require 'sshkit/dsl' 

task :hello => :environment do 
    puts "Hello world" 
end 

task :sshkit_hello => :environment do 
    run_locally do 
    rake "hello" 
    end 
end 

如果我運行:它自己打招呼的任務,我看到「Hello World」的說法。但是,從sshkit任務中調用它,我只需獲取SSHKit信息。如何從SSHKit調用的第一個Rake任務中寫出信息?

rake hello 
=> Hello world 

rake sshkit_hello 
=> INFO [f0857f14] Running /usr/bin/env rake hello on 
=> INFO [f0857f14] Finished in 6.107 seconds with exit status 0 (successful). 

EDIT1:

我發現,你可以添加以下獲得基本的終端輸出:

SSHKit.config.output = $stdout 

但同樣,輸出的信息是相同的 - 它告訴你它運行'rake hello',但不是'rake hello'的輸出。

rake sshkit_hello 
=> rake hello 
+0

它在自述? https://github.com/capistrano/sshkit#output-handling –

+0

我已經通過了,並沒有得到它的工作原理。簡單地添加SSHKit.config.output = SSHKit.config.formatter.new($ stdout)會導致它現在崩潰,因爲格式化程序方法現在是一個私有方法。因此,無論該文檔需要更新或有另一種方式來做到這一點... –

+0

我通過開放性的問題看,並沒有看到任何東西similiar,但'SSHKit.config.formatter'絕對是私人所以你可以嘗試打開一個新的問題。另外 - 查看一些未解決的問題(並重復)我不會認爲這個寶石非常可靠。 –

回答

3

解決!

我真正需要做的是改變output_verbosity到:調試,以便它顯示在第二rake任務賣出期權聲明:

SSHKit.config.output_verbosity = :debug 

rake sshkit_hello 
=> INFO [6dd1bbf7] Running bundle exec rake hello on 
=> DEBUG [6dd1bbf7] Command: bundle exec rake hello 
=> DEBUG [6dd1bbf7]  Hello World! 
=> INFO [6dd1bbf7] Finished in 6.596 seconds with exit status 0 (successful).