From b7c6846e317b0f2bfe4807aab34524c2a633947c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 3 Sep 2009 09:20:42 -0700 Subject: Ensure underlying logger objects are sync=true Userspace buffering defaults are dangerous as the Ruby default IO objects do not do line-aware buffering. This makes the README examples with File.open much safer to use out-of-the-box for users of the pure-Ruby version. For users on the MRI C extension logging to regular files, this should not have any effect as we've optimized those to do unbuffered write(2) syscalls anyways. --- test/test_clogger.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/test_clogger.rb b/test/test_clogger.rb index 8e6604e..d3e315e 100644 --- a/test/test_clogger.rb +++ b/test/test_clogger.rb @@ -434,4 +434,23 @@ class TestClogger < Test::Unit::TestCase assert_equal "text/plain\n", str.string end + def test_clogger_synced + io = StringIO.new + logger = Struct.new(:sync, :io).new(false, io) + assert ! logger.sync + def logger.<<(str) + io << str + end + app = lambda { |env| [302, [ %w(a) ], []] } + cl = Clogger.new(app, :logger => logger) + assert logger.sync + end + + def test_clogger_unsyncable + logger = '' + assert ! logger.respond_to?('sync=') + app = lambda { |env| [302, [ %w(a) ], []] } + assert_nothing_raised { Clogger.new(app, :logger => logger) } + end + end -- cgit v1.2.3-24-ge0c7