Class: Chef::Log

Inherits:
Object
  • Object
show all
Extended by:
Mixlib::Log
Defined in:
lib/chef/log.rb,
lib/chef/log/syslog.rb,
lib/chef/log/winevt.rb

Defined Under Namespace

Classes: Formatter, Syslog, WinEvt

Class Method Summary collapse

Class Method Details

.caller_locationString

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).

Returns:

  • (String)

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



47
48
49
50
51
52
# 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) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# 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