我希望能够从 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 任务,我会看到“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).
编辑1:
我发现您可以添加以下内容以获得基本的终端输出:
SSHKit.config.output = $stdout
但是,同样,输出的信息是相同的——它告诉您它正在运行“rake hello”,而不是“rake hello”的输出。
rake sshkit_hello
=> rake hello
最佳答案
解决了!
我实际上需要做的是将 output_verbosity 更改为 :debug 以便它在第二个 rake 任务中显示 puts 语句:
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).
关于ruby-on-rails - 显示 SSHKit 调用的 rake 任务的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21910685/