summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/logging.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-11-07 15:48:57 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit2292b768c93a1ccba91cfe92d60c65ed936dd45c (patch)
tree0759e4ff470941fc6bb5c9f6b5391b5f430c1291 /lib/puppet/util/logging.rb
parentd93d80a0afdbd53d87dc4a7498609117091e864b (diff)
downloadpuppet-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/puppet/util/logging.rb')
-rw-r--r--lib/puppet/util/logging.rb35
1 files changed, 29 insertions, 6 deletions
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