diff options
-rw-r--r-- | lib/chef/provider/log.rb | 16 | ||||
-rw-r--r-- | lib/chef/resource/log.rb | 62 |
2 files changed, 19 insertions, 59 deletions
diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb index fbbc053b5b..214f284fbb 100644 --- a/lib/chef/provider/log.rb +++ b/lib/chef/provider/log.rb @@ -17,37 +17,27 @@ # class Chef - class Provider - class Log - - # Chef log provider, allows logging to chef's logs from recipes + # Chef log provider, allows logging to chef's logs class ChefLog < Chef::Provider - provides :log # No concept of a 'current' resource for logs, this is a no-op # - # === Return - # true:: Always return true + # @return [true] Always returns true def load_current_resource true end # Write the log to Chef's log # - # === Return - # true:: Always return true + # @return [true] Always returns true def action_write Chef::Log.send(new_resource.level, new_resource.message) new_resource.updated_by_last_action(true) if Chef::Config[:count_log_resource_updates] end - end - end - end - end diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb index 8f7879872f..32d9629b73 100644 --- a/lib/chef/resource/log.rb +++ b/lib/chef/resource/log.rb @@ -18,59 +18,29 @@ # require "chef/resource" -require "chef/provider/log" class Chef class Resource + # Sends a string to a log provider. + # Allows logging a :debug, :info, :warn, and :error levels + # Defaults to :info level + # + # @example logging at default info level + # log "your string to log" + # + # @example logging at specified debug level + # log "a debug string" do + # level :debug + # end + # class Log < Chef::Resource + resource_name :log - identity_attr :message + property :message, String, name_property: true + property :level, Symbol, equal_to: [ :debug, :info, :warn, :error, :fatal ], default: :info + allowed_actions :write default_action :write - - # Sends a string from a recipe to a log provider - # - # log "some string to log" do - # level :info # (default) also supports :warn, :debug, and :error - # end - # - # === Example - # log "your string to log" - # - # or - # - # log "a debug string" { level :debug } - # - - # Initialize log resource with a name as the string to log - # - # === Parameters - # name<String>:: Message to log - # collection<Array>:: Collection of included recipes - # node<Chef::Node>:: Node where resource will be used - def initialize(name, run_context = nil) - super - @level = :info - @message = name - end - - def message(arg = nil) - set_or_return( - :message, - arg, - :kind_of => String - ) - end - - # <Symbol> Log level, one of :debug, :info, :warn, :error or :fatal - def level(arg = nil) - set_or_return( - :level, - arg, - :equal_to => [ :debug, :info, :warn, :error, :fatal ] - ) - end - end end end |