'How to log error messages in chef recipe

How to log the error messages in a recipe.

For EX: My recipe here is

#
# Cookbook:: mkdir
# Recipe:: default
#
# Copyright:: 2018, The Authors, All Rights Reserved.

bash 'extract_module' do
code <<-EOH
mkdir -p /tmp/#{node['main']['directory']}
EOH
Chef::Log.info "Directory Created"
#puts "Directory created"

end

Where is the log file actually created ??? --> Chef::Log.info "Directory Created"

How can i control my recipe to stop if

mkdir -p /tmp/#{node['main']['directory']}

actually fails??

Thank you



Solution 1:[1]

The resource will fail the converge of bash has a non-zero exit code so the easy way is to add set -e to your script. Or use a directory resource instead.

Solution 2:[2]

This was the question that a search found when trying to figure out where Chef Workstation stores the log file (the error when failing to converge was the unhelpful Please examine the log file for a detailed cause of failure but without any indication of where that file should be.

Google was certain that the answer was /var/log/opscode, but it is not.

Ultimately, I found the answer at https://docs.chef.io/workstation/config/#location . This shows how to configure that, and more importantly, that the default is "$USERHOME/.chef-workstation/logs/default.log"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 coderanger
Solution 2 nachbar