【问题标题】:Logging Java Exceptions in Chef在 Chef 中记录 Java 异常
【发布时间】:2015-05-11 16:26:07
【问题描述】:

我正在使用厨师调用一个罐子:

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

现在万一在执行 myjar 时,它会抛出一个异常,在控制台上是不可见的。有什么方法可以在控制台本身中查看相同的内容吗?

【问题讨论】:

  • 您可能应该将其作为服务运行,并将输出发送到日志文件。
  • 必须在控制台上吗?你可以这样做:命令“java -jar myjar.jar > myoutput.txt”然后查看myoutput.txt。
  • 我想到的唯一方法是使用 ruby​​_block 和 Chef::Mixin.shellout,但它非常难看,而且听起来有代码味道,关于用例的更多细节我们可以提供更好的建议。

标签: java chef-infra chef-solo


【解决方案1】:

Chef 不提供任何机制来查看命令命令的输出。解决方法是写入文件然后从中读取。

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

【讨论】:

    猜你喜欢
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多