Permalink
Browse files

set log encoding to BINARY, but still use text mode to output portabl…

…e newlines
  • Loading branch information...
1 parent 78f855c commit a37ae63969c766dcbc7898544de3745227a3130b @fxn fxn committed May 18, 2011
Showing with 9 additions and 6 deletions.
  1. +9 −6 activesupport/lib/active_support/buffered_logger.rb
@@ -48,14 +48,17 @@ def initialize(log, level = DEBUG)
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

0 comments on commit a37ae63

Please sign in to comment.