Sha256: 8070e87091249075580c6158eb7e392a2c40020c15318f7f2e3b89ec0d595f9d

Contents?: true

Size: 1 KB

Versions: 14

Compression:

Stored size: 1 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

  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

14 entries across 14 versions & 1 rubygems

Version Path
puppet-2.6.18 lib/puppet/util/logging.rb
puppet-2.6.17 lib/puppet/util/logging.rb
puppet-2.6.16 lib/puppet/util/logging.rb
puppet-2.6.15 lib/puppet/util/logging.rb
puppet-2.6.14 lib/puppet/util/logging.rb
puppet-2.6.13 lib/puppet/util/logging.rb
puppet-2.6.12 lib/puppet/util/logging.rb
puppet-2.6.11 lib/puppet/util/logging.rb
puppet-2.6.10 lib/puppet/util/logging.rb
puppet-2.6.9 lib/puppet/util/logging.rb
puppet-2.6.8 lib/puppet/util/logging.rb
puppet-2.6.7 lib/puppet/util/logging.rb
puppet-2.6.6 lib/puppet/util/logging.rb
puppet-2.6.5 lib/puppet/util/logging.rb