MikeW
MikeW

Reputation: 4809

How to capture Chef::Log.info in kitchen test

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,

Upvotes: 8

Views: 6240

Answers (2)

David P
David P

Reputation: 839

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.

Upvotes: 13

Martin
Martin

Reputation: 2825

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.

Upvotes: 1

Related Questions