aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-04 19:52:10 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-04 19:52:10 +0000
commitd0755b981470901dc644550f1857f48e7bae6e8a (patch)
treeec016d1ff8b845e535c40b4fc4981550e2fda892 /activesupport
parent41bfedeac273d83585d3cdb2f181ae1978d31adb (diff)
downloadrails-d0755b981470901dc644550f1857f48e7bae6e8a.tar.gz
rails-d0755b981470901dc644550f1857f48e7bae6e8a.tar.bz2
rails-d0755b981470901dc644550f1857f48e7bae6e8a.zip
Disabling auto_flushing still flushes when the buffer hits a maximum size, as a failsafe against memory-gobbling.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7739 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb21
-rw-r--r--activesupport/test/buffered_logger_test.rb13
3 files changed, 24 insertions, 12 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 089c50d545..e621ee2f44 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -2,7 +2,7 @@
* 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]
-* BufferedLogger#auto_flushing = N flushes the log every N messages. Buffers with an array instead of string. [Jeremy Kemper]
+* 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]
* Fixed Date#xmlschema for dates outside the range of what can be created with Time #9744 [Geoff Buesing]
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index 08e71e5b8c..e666b7f0ed 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -11,6 +11,8 @@ module ActiveSupport
end
include Severity
+ MAX_BUFFER_SIZE = 1000
+
# Set to false to disable the silencer
cattr_accessor :silencer
self.silencer = true
@@ -57,7 +59,7 @@ module ActiveSupport
# Ensures that the original message is not mutated.
message = "#{message}\n" unless message[-1] == ?\n
@buffer << message
- auto_flush if auto_flushing
+ auto_flush
message
end
@@ -78,16 +80,13 @@ module ActiveSupport
# never auto-flush. If you turn auto-flushing off, be sure to regularly
# flush the log yourself -- it will eat up memory until you do.
def auto_flushing=(period)
- case period
- when true
- @auto_flushing = 1
- when 0
- @auto_flushing = false
- when false, nil, Integer
- @auto_flushing = period
- else
- raise ArgumentError, "Unrecognized auto_flushing period: #{period.inspect}"
- end
+ @auto_flushing =
+ case period
+ when true; 1
+ when false, nil, 0; MAX_BUFFER_SIZE
+ when Integer; period
+ else raise ArgumentError, "Unrecognized auto_flushing period: #{period.inspect}"
+ end
end
def flush
diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb
index cabdb59045..dc6b59aee9 100644
--- a/activesupport/test/buffered_logger_test.rb
+++ b/activesupport/test/buffered_logger_test.rb
@@ -71,6 +71,19 @@ class BufferedLoggerTest < Test::Unit::TestCase
@logger.flush
assert !@output.string.empty?, @logger.buffer.size
end
+
+ define_method "test_disabling_auto_flush_with_#{disable.inspect}_should_flush_at_max_buffer_size_as_failsafe" do
+ @logger.auto_flushing = disable
+ assert_equal ActiveSupport::BufferedLogger::MAX_BUFFER_SIZE, @logger.auto_flushing
+
+ (ActiveSupport::BufferedLogger::MAX_BUFFER_SIZE - 1).times do
+ @logger.info 'wait for it..'
+ assert @output.string.empty?, @output.string
+ end
+
+ @logger.info 'there it is.'
+ assert !@output.string.empty?, @logger.buffer.size
+ end
end
def test_should_auto_flush_every_n_messages