diff --git a/cookbooks/boxcutter_chef/files/config/attribute_changed_handler.rb b/cookbooks/boxcutter_chef/files/config/attribute_changed_handler.rb index 1194b444..cb3cb0a1 100644 --- a/cookbooks/boxcutter_chef/files/config/attribute_changed_handler.rb +++ b/cookbooks/boxcutter_chef/files/config/attribute_changed_handler.rb @@ -10,19 +10,20 @@ # chefctl -ivd -- --log_level trace Chef.event_handler do on :attribute_changed do |precedence, key, value| + # Do absolutely nothing unless debug logging is enabled + next unless Chef::Log.debug? + # Skip attributes coming from ohai next if precedence == :automatic + Chef::Log.debug('Attributes changed:') + frame = caller.find { |line| line.include?('cookbooks/') } # Example Entry # /etc/cinc/local-mode-cache/cache/cookbooks/fb_apt/resources/sources_list.rb:79:in 'block class_from_file' filename, line_number = frame.split(':') location = "#{filename}:#{line_number}" - puts( - "attribute_changed: key: #{key}, value: #{value}, precedence: #{precedence} at #{location}", - ) - # Trying out improved form - puts( + Chef::Log.debug( "- node.#{precedence}#{key.map { |n| "[\"#{n}\"]" }.join} = #{value} at #{location}", ) end diff --git a/cookbooks/boxcutter_ohai/recipes/default.rb b/cookbooks/boxcutter_ohai/recipes/default.rb index 5bcc0cad..a69b51ca 100644 --- a/cookbooks/boxcutter_ohai/recipes/default.rb +++ b/cookbooks/boxcutter_ohai/recipes/default.rb @@ -41,14 +41,13 @@ on :run_completed do if resource_updates.empty? - # Chef::Log.info('NEW: No resources updated.') - puts('No resources updated.') + Chef::Log.debug('No resources updated.') else - # Chef::Log.info("NEW: Updated #{resource_updates.size} resource(s):") - puts("Updated #{resource_updates.size} resource(s):") + Chef::Log.debug("Updated #{resource_updates.size} resource(s):") resource_updates.each do |r| - # Chef::Log.info("NEW: - #{r[:name]} (#{r[:cookbook]}::#{r[:recipe]} line #{r[:line]}) via :#{r[:action]}") - puts("- #{r[:name]} (#{r[:cookbook]}::#{r[:recipe]} line #{r[:line]}) via :#{r[:action]}") + Chef::Log.debug( + "- #{r[:name]} (#{r[:cookbook]}::#{r[:recipe]} line #{r[:line]}) via :#{r[:action]}", + ) end end end