class Chef::Log

Public Class Methods

caller_location() click to toggle source

Get the location of the caller (from the recipe). Grabs the first caller that is not in the chef gem proper (allowing us to weed out internal calls and give the user a more useful perspective).

@return [String] The location of the caller (file:line#) from caller(0..20), or nil if no non-chef caller is found.

# File lib/chef/log.rb, line 47
def self.caller_location
  # Pick the first caller that is *not* part of the Chef gem, that's the
  # thing the user wrote.
  chef_gem_path = File.expand_path("../..", __FILE__)
  caller(0..20).find { |c| !c.start_with?(chef_gem_path) }
end
deprecation(msg = nil, location = caller(2..2)[0], &block) click to toggle source
# File lib/chef/log.rb, line 54
def self.deprecation(msg = nil, location = caller(2..2)[0], &block)
  if msg
    msg << " at #{Array(location).join("\n")}"
    msg = msg.join("") if msg.respond_to?(:join)
  end
  if Chef::Config[:treat_deprecation_warnings_as_errors]
    error(msg, &block)
    raise Chef::Exceptions::DeprecatedFeatureError.new(msg.inspect)
  else
    warn(msg, &block)
  end
end