diff options
-rw-r--r-- | lib/chef/provider/log.rb | 16 | ||||
-rw-r--r-- | spec/unit/provider/log_spec.rb | 18 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb index 1c970cc888..a98ad1e1a2 100644 --- a/lib/chef/provider/log.rb +++ b/lib/chef/provider/log.rb @@ -25,6 +25,9 @@ class Chef # Chef log provider, allows logging to chef's logs from recipes class ChefLog < Chef::Provider + # ordered array of the log levels + @@levels = [ :debug, :info, :warn, :error, :fatal ] + # No concept of a 'current' resource for logs, this is a no-op # # === Return @@ -39,7 +42,18 @@ class Chef # true:: Always return true def action_write Chef::Log.send(@new_resource.level, @new_resource.message) - @new_resource.updated_by_last_action(true) + + # resolve the integers for the current log levels + global_level = @@levels.index(Chef::Log.level) + resource_level = @@levels.index(@new_resource.level) + + # If the resource level is greater than or the same os the global + # level, then it should have been written to the log. Mark the + # resource as updated. + if resource_level >= global_level + @new_resource.updated_by_last_action(true) + end + end end diff --git a/spec/unit/provider/log_spec.rb b/spec/unit/provider/log_spec.rb index f6ff526dd4..8f411e461a 100644 --- a/spec/unit/provider/log_spec.rb +++ b/spec/unit/provider/log_spec.rb @@ -78,4 +78,22 @@ describe Chef::Provider::Log::ChefLog do @provider.action_write end + it "should not update the resource if the message was not written to the log" do + Chef::Log.level = :fatal + @new_resource = Chef::Resource::Log.new(@log_str) + @new_resource.level :info + @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context) + @provider.action_write + @new_resource.updated.should be_false + end + + it "should update the resource if the message has been written to the log" do + Chef::Log.level = :debug + @new_resource = Chef::Resource::Log.new(@log_str) + @new_resource.level :info + @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context) + @provider.action_write + @new_resource.updated.should be_true + end + end |