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. Or failing that, the most recent caller.
  chef_gem_path = File.expand_path("../..", __FILE__)
  caller(0..20).find { |c| !c.start_with?(chef_gem_path) } || caller(0..1)[0]
end

.deprecation(msg, &block) ⇒ Object

Log a deprecation warning.

If the treat_deprecation_warnings_as_errors config option is set, this will raise an exception instead.

Parameters:

  • msg (String)

    Deprecation message to display.


60
61
62
63
64
65
66
67
# File 'lib/chef/log.rb', line 60

def self.deprecation(msg, &block)
  if Chef::Config[:treat_deprecation_warnings_as_errors]
    error(msg, &block)
    raise Chef::Exceptions::DeprecatedFeatureError.new(msg)
  else
    warn(msg, &block)
  end
end