简体   繁体   English

在Chef中记录Java异常

[英]Logging Java Exceptions in Chef

I am invoking a jar using chef like : 我正在使用如下厨师使用罐子:

execute "publish" do
  Chef::Log.info("About to published")
  command "java -jar myjar.jar"
  Chef::Log.info("Published")      
end

Now in case while executing myjar, it throws an exception, the same is not visible on the console. 现在以防万一,在执行myjar时会引发异常,该异常在控制台上不可见。 Is there some way by which the same can be viewed in the console itself ? 是否可以通过某种方式在控制台本身中查看它们?

Chef does not provide any mechanism to view the output of a command diect. Chef不提供任何机制来查看命令Diect的输出。 The workaround is to write to a file & then read from it. 解决方法是先写入文件,然后再读取文件。

output  = "/tmp/output.tmp"


execute "publish" do
  Chef::Log.info("About to published")
  command command "java -jar myjar.jar &> #{output}"
  action :run
  Chef::Log.info("Published")
end

# Outputting logs to console
ruby_block "log" do
    block do
        print "\n"
        File.open(output).each do |line|
            print line
        end
    end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM