summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-10-03 17:35:45 -0500
committerJames Turnbull <james@lovedthanlost.net>2008-10-04 08:48:16 +1000
commitdb7f108f546db2114f87316c68d33706c9e4142e (patch)
tree76043c3a9a6dc7253b05e569bf10807b76b226c5 /lib
parentd2c89985bb356188ac52d00b0799cae655a9c75b (diff)
downloadpuppet-db7f108f546db2114f87316c68d33706c9e4142e.tar.gz
puppet-db7f108f546db2114f87316c68d33706c9e4142e.tar.xz
puppet-db7f108f546db2114f87316c68d33706c9e4142e.zip
Adding rspec tests for the Puppet::Util::Log class.
Also using Puppet::Util::Tagging to handle the tagging, rather than custom methods. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/util/log.rb27
1 files changed, 11 insertions, 16 deletions
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index 8824a8b50..f5119bbff 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -1,10 +1,12 @@
require 'syslog'
+require 'puppet/util/tagging'
# Pass feedback to the user. Log levels are modeled after syslog's, and it is
# expected that that will be the most common log destination. Supports
# multiple destinations, one of which is a remote server.
class Puppet::Util::Log
include Puppet::Util
+ include Puppet::Util::Tagging
@levels = [:debug,:info,:notice,:warning,:err,:alert,:emerg,:crit]
@loglevel = 2
@@ -470,12 +472,12 @@ class Puppet::Util::Log
@levels.include?(level)
end
- attr_accessor :level, :message, :time, :tags, :remote
+ attr_accessor :level, :message, :time, :remote
attr_reader :source
def initialize(args)
unless args.include?(:level) && args.include?(:message)
- raise Puppet::DevError, "Puppet::Util::Log called incorrectly"
+ raise ArgumentError, "Puppet::Util::Log called incorrectly"
end
if args[:level].class == String
@@ -483,8 +485,7 @@ class Puppet::Util::Log
elsif args[:level].class == Symbol
@level = args[:level]
else
- raise Puppet::DevError,
- "Level is not a string or symbol: #{args[:level].class}"
+ raise ArgumentError, "Level is not a string or symbol: #{args[:level].class}"
end
# Just return unless we're actually at a level we should send
@@ -495,11 +496,11 @@ class Puppet::Util::Log
# this should include the host name, and probly lots of other
# stuff, at some point
unless self.class.validlevel?(level)
- raise Puppet::DevError, "Invalid message level #{level}"
+ raise ArgumentError, "Invalid message level #{level}"
end
- if args.include?(:tags)
- @tags = args[:tags]
+ if tags = args[:tags]
+ tags.each { |t| self.tag(t) }
end
if args.include?(:source)
@@ -511,7 +512,7 @@ class Puppet::Util::Log
Log.newmessage(self)
end
- # Was the source of this log an object?
+ # Was the source of this log a Puppet resource or parameter?
def objectsource?
if defined? @objectsource and @objectsource
@objectsource
@@ -533,17 +534,11 @@ class Puppet::Util::Log
@objectsource = false
@source = source.to_s
end
- unless defined? @tags and @tags
- if source.respond_to?(:tags)
- @tags = source.tags
- end
+ if source.respond_to?(:tags)
+ source.tags.each { |t| tag(t) }
end
end
- def tagged?(tag)
- @tags.detect { |t| t.to_s == tag.to_s }
- end
-
def to_report
"%s %s (%s): %s" % [self.time, self.source, self.level, self.to_s]
end