From 9d8e2fb5e21da725755366ae2b7affe83ce1b6b0 Mon Sep 17 00:00:00 2001
From: Xavier Noria <fxn@hashref.com>
Date: Wed, 18 May 2011 12:43:29 +0200
Subject: set log encoding to BINARY, but still use text mode to output
 portable newlines

---
 activesupport/lib/active_support/buffered_logger.rb | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index a14f008be5..b937d4c50d 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -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
 
-- 
cgit v1.2.3