Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7739

Show
Ignore:
Timestamp:
10/04/07 19:52:10 (1 year ago)
Author:
bitsweat
Message:

Disabling auto_flushing still flushes when the buffer hits a maximum size, as a failsafe against memory-gobbling.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r7736 r7739  
    33* Hash#to_json takes :only or :except options to specific or omit certain hash keys. Enumerable#to_json passes through its options to each element.  #9751 [Chu Yeow] 
    44 
    5 * BufferedLogger#auto_flushing = N flushes the log every N messages. Buffers with an array instead of string. [Jeremy Kemper] 
     5* BufferedLogger#auto_flushing = N flushes the log every N messages. Buffers with an array instead of string. Disabling auto_flushing still flushes when the buffer hits a maximum size, as a failsafe against memory-gobbling. [Jeremy Kemper] 
    66 
    77* Fixed Date#xmlschema for dates outside the range of what can be created with Time #9744 [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/buffered_logger.rb

    r7734 r7739  
    1111    end 
    1212    include Severity 
     13 
     14    MAX_BUFFER_SIZE = 1000 
    1315 
    1416    # Set to false to disable the silencer 
     
    5860      message = "#{message}\n" unless message[-1] == ?\n 
    5961      @buffer << message 
    60       auto_flush if auto_flushing 
     62      auto_flush 
    6163      message 
    6264    end 
     
    7981    # flush the log yourself -- it will eat up memory until you do. 
    8082    def auto_flushing=(period) 
    81       case period 
    82       when true 
    83         @auto_flushing = 1 
    84       when 0 
    85         @auto_flushing = false 
    86       when false, nil, Integer 
    87         @auto_flushing = period 
    88       else 
    89         raise ArgumentError, "Unrecognized auto_flushing period: #{period.inspect}" 
    90       end 
     83      @auto_flushing = 
     84        case period 
     85        when true;                1 
     86        when false, nil, 0;       MAX_BUFFER_SIZE 
     87        when Integer;             period 
     88        else raise ArgumentError, "Unrecognized auto_flushing period: #{period.inspect}" 
     89        end 
    9190    end 
    9291 
  • trunk/activesupport/test/buffered_logger_test.rb

    r7732 r7739  
    7272      assert !@output.string.empty?, @logger.buffer.size 
    7373    end 
     74 
     75    define_method "test_disabling_auto_flush_with_#{disable.inspect}_should_flush_at_max_buffer_size_as_failsafe" do 
     76      @logger.auto_flushing = disable 
     77      assert_equal ActiveSupport::BufferedLogger::MAX_BUFFER_SIZE, @logger.auto_flushing 
     78 
     79      (ActiveSupport::BufferedLogger::MAX_BUFFER_SIZE - 1).times do 
     80        @logger.info 'wait for it..' 
     81        assert @output.string.empty?, @output.string 
     82      end 
     83 
     84      @logger.info 'there it is.' 
     85      assert !@output.string.empty?, @logger.buffer.size 
     86    end 
    7487  end 
    7588