[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:30:52 UTC 2010


The following commit has been merged in the upstream branch:
commit 5776fe4e33b5bb3399a2e72d76faeffb2bba1f4e
Author: Luke Kanies <luke at madstop.com>
Date:   Sat Nov 7 15:53:22 2009 -0600

    Cleaning up the Log initialization code.
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index e3930fb..c64cbe5 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -207,36 +207,40 @@ class Puppet::Util::Log
         @levels.include?(level)
     end
 
-    attr_accessor :level, :message, :time, :remote, :file, :line, :version, :source
+    attr_accessor :time, :remote, :file, :line, :version, :source
+    attr_reader :level, :message
 
     def initialize(args)
-        unless args.include?(:level) && args.include?(:message)
-            raise ArgumentError, "Puppet::Util::Log called incorrectly"
-        end
-
-        if args[:level].class == String
-            @level = args[:level].intern
-        elsif args[:level].class == Symbol
-            @level = args[:level]
-        else
-            raise ArgumentError, "Level is not a string or symbol: #{args[:level].class}"
-        end
+        self.level = args[:level]
+        self.message = args[:message]
+        self.source = args[:source] || "Puppet"
 
-        @message = args[:message].to_s
         @time = Time.now
 
-        raise ArgumentError, "Invalid log level %s" % level unless self.class.validlevel?(level)
-
         if tags = args[:tags]
             tags.each { |t| self.tag(t) }
         end
 
-        self.source = args[:source] || "Puppet"
+        [:file, :line, :version].each do |attr|
+            next unless value = args[attr]
+            send(attr.to_s + "=", value)
+        end
+
+        Log.newmessage(self)
+    end
+    
+    def message=(msg)
+        raise ArgumentError, "Puppet::Util::Log requires a message" unless msg
+        @message = msg.to_s
+    end
+
+    def level=(level)
+        raise ArgumentError, "Puppet::Util::Log requires a log level" unless level
+        @level = level.to_sym
+        raise ArgumentError, "Invalid log level %s" % @level unless self.class.validlevel?(@level)
 
         # Tag myself with my log level
         tag(level)
-
-        Log.newmessage(self)
     end
 
     # If they pass a source in to us, we make sure it is a string, and
@@ -258,11 +262,11 @@ class Puppet::Util::Log
     end
 
     def to_report
-        "%s %s (%s): %s" % [self.time, self.source, self.level, self.to_s]
+        "#{time} #{source} (#{level}): #{to_s}"
     end
 
     def to_s
-        return @message
+        message
     end
 end
 
diff --git a/spec/unit/util/log.rb b/spec/unit/util/log.rb
index 97fb2f2..7aaa580 100755
--- a/spec/unit/util/log.rb
+++ b/spec/unit/util/log.rb
@@ -114,6 +114,13 @@ describe Puppet::Util::Log do
             Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => "foo")
         end
 
+        [:file, :line, :version].each do |attr|
+            it "should use #{attr} if provided" do
+                Puppet::Util::Log.any_instance.expects(attr.to_s + "=").with "foo"
+                Puppet::Util::Log.new(:level => "notice", :message => :foo, attr => "foo")
+            end
+        end
+
         it "should default to 'Puppet' as its source" do
             Puppet::Util::Log.new(:level => "notice", :message => :foo).source.should == "Puppet"
         end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list