set log encoding to BINARY, but still use text mode to output portable newlines

This commit is contained in:
Xavier Noria
2011-05-18 12:43:29 +02:00
parent 2692d3278a
commit 9d8e2fb5e2

View File

@@ -48,14 +48,17 @@ module ActiveSupport
if log.respond_to?(:write)
@log = log
elsif File.exist?(log)
@log = open(log, (File::WRONLY | File::APPEND))
@log.binmode
@log.sync = true
@log = open_log(log, (File::WRONLY | File::APPEND))
else
FileUtils.mkdir_p(File.dirname(log))
@log = open(log, (File::WRONLY | File::APPEND | File::CREAT))
@log.binmode
@log.sync = true
@log = open_log(log, (File::WRONLY | File::APPEND | File::CREAT))
end
end
def open_log(log, mode)
open(log, mode).tap do |log|
log.set_encoding(Encoding::BINARY) if log.respond_to?(:set_encoding)
log.sync = true
end
end