How to capture Chef::Log.info in kitchen test
Asked Answered
P

2

8

When I run

   kitchen test

or

   kitchen test --log-level info

No logs that I have in my recipe under test ie.

   Chef::Log.info("How to make appear in kitchen output?")

are displayed in kitchen's output to console. Anyway to make this happen?

driver: vagrant

provisioner: chef-solo

Thanks,

Phraseograph answered 22/9, 2015 at 20:47 Comment(0)
T
13

Update: Martin's answer is no longer true as of version 1.7.0 of Test Kitchen (See pull request #950).

According to the Dynamic Configuration doc, "Since Kitchen 1.7.0 the log level for the provisioner is no longer related to the Kitchen log level."

It gives the following example of setting the log_level in .kitchen.yml:

provisioner: name: chef-zero log_level: <%= ENV['CHEF_LOG_LEVEL'] || auto %>

My tests confirm that:

  • Chef::Log.debug calls aren't logged when simply running kitchen converge -l debug.
  • Chef::Log.debug calls are logged after setting log_level: debug in .kitchen.yml.
Tirade answered 5/5, 2017 at 4:32 Comment(1)
Note that the log_level option is not currently documented in the .kitchen.yml syntax doc. See also v1.7.0 entry in the CHANGELOGTirade
C
1

You can set the verbose level when running test-kitchen, e.g. kitchen test -l debug. What you're seeing is that by default, Chef runs at WARN and higher, so by default, INFO is hidden. This is true with chef-client as well. Using -l debug on your kitchen command will pass -l debug to the chef-client command, and then you'll see INFO-level logs too.

Croatia answered 23/9, 2015 at 1:3 Comment(2)
Hi - I've tried this but still aren't seeing any logs from the recipe - does this apply to chef-solo ? -- actually disregard - docs say it does - ill try a few different log levels and see what happensPhraseograph
I use this all the time, so I'm pretty sure that is correct. I only use it with -l debug though.Croatia

© 2022 - 2024 — McMap. All rights reserved.