如何在测试厨房中获取日志输出? [英] How do I get log output in test kitchen?

查看:130
本文介绍了如何在测试厨房中获取日志输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的食谱中有这个

log mylog1 do
  level :info
  message 'WHY I NO SEE THIS?'
end
log mylog2 do
  level :info
  message 'WHY I NO SEE THIS?'
end

这是我在进行厨房融合-l调试时看到的内容

...
Converging 3 resources
Recipe: mybook::myrecipe
  * log[mylog1] action write
  * log[mylog1] action write
...


推荐答案

这个问题有两个部分:

首先,日志级别通过 -l debug适用于 kitchen可执行文件,而不适用于 provisioner ,在这种情况下为 chef-solo 。因此,如果使用带调试选项的厨房运行,您会看到预配置程序正在以 log_level 作为 自动

First, The log level passed to kitchen with "-l debug" is for the kitchen executable and not for the provisioner, in this case "chef-solo". Therefore, if you run the kitchen with debug option, you would see that, provisioner is running with log_level as "auto" as below, even when kitchen in debug mode:

[SSH] vagrant@127.0.0.1<{:user_known_hosts_file=>"/dev/null",
:paranoid=>false, :port=>"2222", :compression=>false, :compression_level=>0,
:keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true,
:keys=>["/Users/mpriyada/myWorks/.kitchen/kitchen-vagrant/kitchen-default-centos/.vagrant/machines/default/virtualbox/private_key"],
:auth_methods=>["publickey"], :user=>"vagrant"}> (sh -c 'sudo -E /opt/chef/bin/chef-solo
--config /tmp/kitchen/solo.rb --log_level auto --force-formatter --no-color
--json-attributes /tmp/kitchen/dna.json')

这意味着Chef-solo日志记录优先级 自动 警告 级别相同。 因此,如果在 log资源中将日志级别设置为info,则不会记录任何输出。 试试下面的代码,您会发现差异:

Which means that, in chef-solo logging priority, "auto" comes par with "warn" level. And hence no output is logged if log level is set as info in the "log" resource. Try below code, you observe the difference:

log "mylog1" do
   level :warn
   message 'WHY I NO SEE THIS?'
end

log "mylog2" do
   level :info
   message 'WHY I NO SEE THIS?'
end

输出:

Recipe: test3::default
   * log[mylog1] action write[2016-08-17T03:55:16+00:00] WARN: WHY I NO SEE THIS?      

   * log[mylog2] action write
Running handlers:
Running handlers complete

现在,第二部分,如果您不想在 自动 log_level 中运行厨房,您可以转到 /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.10.0/lib/kitchen/provisioner/chef_base.rb ,并将硬编码日志级别 auto 更改为任何 chef-solo > 日志记录许可 https://docs.chef.io/config_rb_solo.html

Now, Second part, if you don't want to run your kitchen in "auto" log_level, you can go to "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.10.0/lib/kitchen/provisioner/chef_base.rb" and change the hard coded log level from auto to whatever chef-solo logging permits https://docs.chef.io/config_rb_solo.html.

这篇关于如何在测试厨房中获取日志输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆