Jakir00
Jakir00

Reputation: 2073

Write to Chef::Log from a template script?

I work on a team that decided long ago to use Chef's template resource to make dynamic scripts to be executed in an execute reource block.

I know this feature was only built to generate config files and the like, but I have to work with what I've got here.

Basically I need to know how to write to Chef::Log from a Ruby script generated from a template block. The script is not in the same context as the cookbook that generated it, so I can't just call require 'chef/log' in the script. I also do not want to just append the chef-run.log because that runs into timing problems.

Is there any way to accomplish this as cleanly as possible without appending to chef-run.log?

Thank you for your time.

Upvotes: 0

Views: 338

Answers (1)

coderanger
coderanger

Reputation: 54181

Chef::Log is a global, so technically you can just call its methods directly from inside a template, but this is really weird and you probably shouldn't. Do whatever logging you need from the recipe code instead. If you need to log some values, compute them in the recipe and them pass them in using variables.

Upvotes: 1

Related Questions