diff options
Diffstat (limited to 'lib/puppet/util.rb')
-rw-r--r-- | lib/puppet/util.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 50f488905..6169bde81 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -85,6 +85,43 @@ module Util return retval end + # Capture stderr of a block + def self.capture_stderr + require 'stringio' + begin + $stderr = StringIO.new + yield + $stderr.rewind && $stderr.read + ensure + $stderr = STDERR + end + end + + # Create instance methods for each of the log levels. This allows + # the messages to be a little richer. Most classes will be calling this + # method. + def self.logmethods(klass, useself = true) + Puppet::Log.eachlevel { |level| + klass.send(:define_method, level, proc { |args| + if args.is_a?(Array) + args = args.join(" ") + end + if useself + Puppet::Log.create( + :level => level, + :message => args + ) + else + Puppet::Log.create( + :level => level, + :source => self, + :message => args + ) + end + }) + } + end + # XXX this should all be done using puppet objects, not using # normal mkdir def self.recmkdir(dir,mode = 0755) |