diff options
author | Luke Kanies <luke@madstop.com> | 2009-11-07 15:48:57 -0600 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 2292b768c93a1ccba91cfe92d60c65ed936dd45c (patch) | |
tree | 0759e4ff470941fc6bb5c9f6b5391b5f430c1291 /lib | |
parent | d93d80a0afdbd53d87dc4a7498609117091e864b (diff) | |
download | puppet-2292b768c93a1ccba91cfe92d60c65ed936dd45c.tar.gz puppet-2292b768c93a1ccba91cfe92d60c65ed936dd45c.tar.xz puppet-2292b768c93a1ccba91cfe92d60c65ed936dd45c.zip |
Refactoring the RAL interface to logging
Previously, the Log class knew a lot about RAL objects,
but now the Logging module is the only one that does.
This greatly simplifies the Log class, which is good,
and means that whatever complexity does need to exist
is directly exposed in the Logging middleware module.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parameter.rb | 11 | ||||
-rw-r--r-- | lib/puppet/util/log.rb | 3 | ||||
-rw-r--r-- | lib/puppet/util/log/destinations.rb | 5 | ||||
-rw-r--r-- | lib/puppet/util/logging.rb | 35 |
4 files changed, 34 insertions, 20 deletions
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index 0e4071cc5..285a205da 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -205,17 +205,8 @@ class Puppet::Parameter set_options(options) end - # Log a message using the resource's log level. def log(msg) - unless @resource[:loglevel] - self.devfail "Parent %s has no loglevel" % - @resource.name - end - Puppet::Util::Log.create( - :level => @resource[:loglevel], - :message => msg, - :source => self - ) + send_log(resource[:loglevel], msg) end # Is this parameter a metaparam? 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 |