diff options
author | Xavier Noria <fxn@hashref.com> | 2011-05-18 12:43:29 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-05-18 12:43:29 +0200 |
commit | 9d8e2fb5e21da725755366ae2b7affe83ce1b6b0 (patch) | |
tree | 45b7768453d0cee00dbbb2975b2c1204f901fec6 /activesupport/lib/active_support | |
parent | 2692d3278a7b15699491f8c86b4180eaad9ce196 (diff) | |
download | rails-9d8e2fb5e21da725755366ae2b7affe83ce1b6b0.tar.gz rails-9d8e2fb5e21da725755366ae2b7affe83ce1b6b0.tar.bz2 rails-9d8e2fb5e21da725755366ae2b7affe83ce1b6b0.zip |
set log encoding to BINARY, but still use text mode to output portable newlines
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/buffered_logger.rb | 15 |
1 files 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 |