Skip to content

Commit cb2466f

Browse files
committed
Only output handler tracing when in debug mode
1 parent 8a5a580 commit cb2466f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

cookbooks/boxcutter_chef/files/config/attribute_changed_handler.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
# chefctl -ivd -- --log_level trace
1111
Chef.event_handler do
1212
on :attribute_changed do |precedence, key, value|
13+
# Do absolutely nothing unless debug logging is enabled
14+
next unless Chef::Log.debug?
15+
1316
# Skip attributes coming from ohai
1417
next if precedence == :automatic
1518

19+
Chef::Log.debug("Attributes changed:")
20+
1621
frame = caller.find { |line| line.include?('cookbooks/') }
1722
# Example Entry
1823
# /etc/cinc/local-mode-cache/cache/cookbooks/fb_apt/resources/sources_list.rb:79:in 'block class_from_file'
1924
filename, line_number = frame.split(':')
2025
location = "#{filename}:#{line_number}"
21-
puts(
22-
"attribute_changed: key: #{key}, value: #{value}, precedence: #{precedence} at #{location}",
23-
)
24-
# Trying out improved form
25-
puts(
26+
Chef::Log.debug(
2627
"- node.#{precedence}#{key.map { |n| "[\"#{n}\"]" }.join} = #{value} at #{location}",
2728
)
2829
end

cookbooks/boxcutter_ohai/recipes/default.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@
4141

4242
on :run_completed do
4343
if resource_updates.empty?
44-
# Chef::Log.info('NEW: No resources updated.')
45-
puts('No resources updated.')
44+
Chef::Log.debug('No resources updated.')
4645
else
47-
# Chef::Log.info("NEW: Updated #{resource_updates.size} resource(s):")
48-
puts("Updated #{resource_updates.size} resource(s):")
46+
Chef::Log.debug("Updated #{resource_updates.size} resource(s):")
4947
resource_updates.each do |r|
50-
# Chef::Log.info("NEW: - #{r[:name]} (#{r[:cookbook]}::#{r[:recipe]} line #{r[:line]}) via :#{r[:action]}")
51-
puts("- #{r[:name]} (#{r[:cookbook]}::#{r[:recipe]} line #{r[:line]}) via :#{r[:action]}")
48+
Chef::Log.debug(
49+
"- #{r[:name]} (#{r[:cookbook]}::#{r[:recipe]} line #{r[:line]}) via :#{r[:action]}"
50+
)
5251
end
5352
end
5453
end

0 commit comments

Comments
 (0)