diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-10 13:21:58 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-10 13:23:05 -0700 |
commit | 8f999a3f80284e08804c374cb5690c8bc158e4c1 (patch) | |
tree | 7815d7cd838a2c61e66e9d367c8e7c9f78ce4207 /activesupport | |
parent | 7b6819f985bf26f160382e8d1b255f9a4b6436e4 (diff) | |
download | rails-8f999a3f80284e08804c374cb5690c8bc158e4c1.tar.gz rails-8f999a3f80284e08804c374cb5690c8bc158e4c1.tar.bz2 rails-8f999a3f80284e08804c374cb5690c8bc158e4c1.zip |
make sure log file is written in binary mode. fixes #497
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/buffered_logger.rb | 2 | ||||
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 39 |
2 files changed, 41 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index 88b50fc506..a14f008be5 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -49,10 +49,12 @@ module ActiveSupport @log = log elsif File.exist?(log) @log = open(log, (File::WRONLY | File::APPEND)) + @log.binmode @log.sync = true else FileUtils.mkdir_p(File.dirname(log)) @log = open(log, (File::WRONLY | File::APPEND | File::CREAT)) + @log.binmode @log.sync = true end end diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 8d1b1c02c6..21049d685b 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require 'multibyte_test_helpers' require 'stringio' require 'fileutils' +require 'tempfile' require 'active_support/buffered_logger' class BufferedLoggerTest < Test::Unit::TestCase @@ -16,6 +17,44 @@ class BufferedLoggerTest < Test::Unit::TestCase @logger = Logger.new(@output) end + def test_write_binary_data_to_existing_file + t = Tempfile.new ['development', 'log'] + t.binmode + t.write 'hi mom!' + t.close + + logger = Logger.new t.path + logger.level = Logger::DEBUG + + str = "\x80" + if str.respond_to?(:force_encoding) + str.force_encoding("ASCII-8BIT") + end + + logger.add Logger::DEBUG, str + logger.flush + ensure + logger.close + t.close true + end + + def test_write_binary_data_create_file + fname = File.join Dir.tmpdir, 'lol', 'rofl.log' + logger = Logger.new fname + logger.level = Logger::DEBUG + + str = "\x80" + if str.respond_to?(:force_encoding) + str.force_encoding("ASCII-8BIT") + end + + logger.add Logger::DEBUG, str + logger.flush + ensure + logger.close + File.unlink fname + end + def test_should_log_debugging_message_when_debugging @logger.level = Logger::DEBUG @logger.add(Logger::DEBUG, @message) |