summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/log.rb3
-rw-r--r--lib/puppet/util/log/destinations.rb5
-rw-r--r--lib/puppet/util/logging.rb35
3 files changed, 33 insertions, 10 deletions
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index 50111ab0d..e3930fbe4 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -207,8 +207,7 @@ class Puppet::Util::Log
@levels.include?(level)
end
- attr_accessor :level, :message, :time, :remote, :file, :line, :version
- attr_reader :source
+ attr_accessor :level, :message, :time, :remote, :file, :line, :version, :source
def initialize(args)
unless args.include?(:level) && args.include?(:message)
diff --git a/lib/puppet/util/log/destinations.rb b/lib/puppet/util/log/destinations.rb
index 89f87dbec..002ca3624 100644
--- a/lib/puppet/util/log/destinations.rb
+++ b/lib/puppet/util/log/destinations.rb
@@ -113,9 +113,10 @@ Puppet::Util::Log.newdesttype :console do
def colorize(level, str)
case Puppet[:color]
- when false; str
- when true, :ansi, "ansi"; console_color(level, str)
+ when true, :ansi, "ansi", "yes"; console_color(level, str)
when :html, "html"; html_color(level, str)
+ else
+ str
end
end
diff --git a/lib/puppet/util/logging.rb b/lib/puppet/util/logging.rb
index 13480743c..3af698062 100644
--- a/lib/puppet/util/logging.rb
+++ b/lib/puppet/util/logging.rb
@@ -2,18 +2,41 @@
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|
if args.is_a?(Array)
args = args.join(" ")
end
- Puppet::Util::Log.create(
- :level => level,
- :source => self,
- :message => args
- )
+ send_log(level, args)
end
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, :version, :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
+ return to_s
+ end
+end