Sha256: 874a77151422ffbbe49c177c9d778692a1cf1dbdff0d519601edb429f47bbaa7

Contents?: true

Size: 1.3 KB

Versions: 44

Compression:

Stored size: 1.3 KB

Contents

# A module to make logging a bit easier.
require 'puppet/util/log'

module Puppet::Util::Logging

  def send_log(level, message)
    Puppet::Util::Log.create({:level => level, :source => log_source, :message => message}.merge(log_metadata))
  end

  # Create a method for each log level.
  Puppet::Util::Log.eachlevel do |level|
    define_method(level) do |args|
      args = args.join(" ") if args.is_a?(Array)
      send_log(level, args)
    end
  end

  def deprecation_warning(message)
    $deprecation_warnings ||= Hash.new(0)
    if $deprecation_warnings.length < 100 and ($deprecation_warnings[message] += 1) == 1
      warning message
    end
  end

  def clear_deprecation_warnings
    $deprecation_warnings.clear if $deprecation_warnings
  end

  private

  def is_resource?
    defined?(Puppet::Type) && is_a?(Puppet::Type)
  end

  def is_resource_parameter?
    defined?(Puppet::Parameter) && is_a?(Puppet::Parameter)
  end

  def log_metadata
    [:file, :line, :tags].inject({}) do |result, attr|
      result[attr] = send(attr) if respond_to?(attr)
      result
    end
  end

  def log_source
    # We need to guard the existence of the constants, since this module is used by the base Puppet module.
    (is_resource? or is_resource_parameter?) and respond_to?(:path) and return path.to_s
    to_s
  end
end

Version data entries

44 entries across 44 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/util/logging.rb
puppet-parse-0.1.3 lib/vendor/puppet/util/logging.rb
puppet-parse-0.1.2 lib/vendor/puppet/util/logging.rb
puppet-parse-0.1.1 lib/vendor/puppet/util/logging.rb
puppet-2.7.26 lib/puppet/util/logging.rb
puppet-2.7.25 lib/puppet/util/logging.rb
puppet-2.7.24 lib/puppet/util/logging.rb
puppet-2.7.23 lib/puppet/util/logging.rb
puppet-2.7.22 lib/puppet/util/logging.rb
puppet-parse-0.1.0 lib/vendor/puppet/util/logging.rb
puppet-parse-0.0.6 lib/vendor/puppet/util/logging.rb
puppet-2.7.21 lib/puppet/util/logging.rb
puppet-parse-0.0.5 lib/vendor/puppet/util/logging.rb
puppet-parse-0.0.4 lib/vendor/puppet/util/logging.rb
puppet-parse-0.0.2 lib/vendor/puppet/util/logging.rb
puppet-2.7.20 lib/puppet/util/logging.rb
puppet-2.7.20.rc1 lib/puppet/util/logging.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/util/logging.rb
puppet-2.7.19 lib/puppet/util/logging.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/logging.rb