If we fix the Hash#count to something that exists on old rubies, I'll
happily +1 this.

On Tue, Jul 6, 2010 at 2:06 PM, Nick Lewis <[email protected]> wrote:
> Apologies, this is actually for ticket #4114. I've amended the commit message.
>
> On Jul 6, 2010, at 1:36 PM, Nick Lewis wrote:
>
>> The log will now queue any log messages created when there is no
>> destination, and will flush the queue when a destination is added.
>>
>> Signed-off-by: Nick Lewis <[email protected]>
>> ---
>> lib/puppet/util/log.rb         |   17 +++++++++++++++++
>> spec/unit/util/log_spec.rb     |    6 ++++++
>> spec/unit/util/logging_spec.rb |    6 ++++++
>> 3 files changed, 29 insertions(+), 0 deletions(-)
>>
>> diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
>> index ba23e12..64a8d14 100644
>> --- a/lib/puppet/util/log.rb
>> +++ b/lib/puppet/util/log.rb
>> @@ -31,6 +31,8 @@ class Puppet::Util::Log
>>
>>     @destinations = {}
>>
>> +   �...@queued = []
>> +
>>     class << self
>>         include Puppet::Util
>>         include Puppet::Util::ClassGen
>> @@ -145,6 +147,7 @@ class Puppet::Util::Log
>>             else
>>                 @destinations[dest] = type.new()
>>             end
>> +            flushqueue
>>         rescue => detail
>>             if Puppet[:debug]
>>                 puts detail.backtrace
>> @@ -167,6 +170,8 @@ class Puppet::Util::Log
>>             return
>>         end
>>
>> +        queuemessage(msg) if @destinations.count == 0
>> +
>>         @destinations.each do |name, dest|
>>             threadlock(dest) do
>>                 dest.handle(msg)
>> @@ -174,6 +179,18 @@ class Puppet::Util::Log
>>         end
>>     end
>>
>> +    def Log.queuemessage(msg)
>> +       �[email protected](msg)
>> +    end
>> +
>> +    def Log.flushqueue
>> +        return unless @destinations.size >= 1
>> +       �[email protected] do |msg|
>> +            Log.newmessage(msg)
>> +        end
>> +       �[email protected]
>> +    end
>> +
>>     def Log.sendlevel?(level)
>>         @levels.index(level) >= @loglevel
>>     end
>> diff --git a/spec/unit/util/log_spec.rb b/spec/unit/util/log_spec.rb
>> index 7aaa580..c72078f 100755
>> --- a/spec/unit/util/log_spec.rb
>> +++ b/spec/unit/util/log_spec.rb
>> @@ -84,6 +84,12 @@ describe Puppet::Util::Log do
>>             Puppet::Util::Log.new(:level => :notice, :message => 
>> :foo).message.should == "foo"
>>         end
>>
>> +        it "should write queued logs when the first destination is 
>> specified" do
>> +            Hash.any_instance.stubs(:[]=)
>> +            Puppet::Util::Log.expects(:flushqueue)
>> +            Puppet::Util::Log.newdestination(:console)
>> +        end
>> +
>>         it "should convert the level to a symbol if it's passed in as a 
>> string" do
>>             Puppet::Util::Log.new(:level => "notice", :message => 
>> :foo).level.should == :notice
>>         end
>> diff --git a/spec/unit/util/logging_spec.rb b/spec/unit/util/logging_spec.rb
>> index aee308e..41b07d4 100755
>> --- a/spec/unit/util/logging_spec.rb
>> +++ b/spec/unit/util/logging_spec.rb
>> @@ -40,6 +40,12 @@ describe Puppet::Util::Logging do
>>             @logger.notice "foo"
>>         end
>>
>> +        it "should queue logs sent without a specified destination" do
>> +            Puppet::Util::Log.expects(:queuemessage)
>> +
>> +           �[email protected] "foo"
>> +        end
>> +
>>         it "should use the path of any provided resource type" do
>>             resource = Puppet::Type.type(:mount).new :name => "foo"
>>
>> --
>> 1.7.1
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Puppet Developers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/puppet-dev?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/puppet-dev?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to