1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

make sure log file is written in binary mode. fixes #497

This commit is contained in:
Aaron Patterson 2011-05-10 13:21:58 -07:00
parent 7b6819f985
commit 8f999a3f80
2 changed files with 41 additions and 0 deletions

View file

@ -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

View file

@ -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)