summaryrefslogtreecommitdiff
path: root/test/logger/test_logger.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2019-06-04 18:07:26 -0400
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-07-15 14:43:08 +0900
commit58065b87018a9d1ed972b8c856004bf75728da02 (patch)
treef3326bd6aab14ee2204f3fec842515821778cc1a /test/logger/test_logger.rb
parentf4064a0a0c24734b1ec98e6e2dbdf5e38e856c41 (diff)
[ruby/logger] Add option to set the binary mode of the log device
Without binmode strings with incompatible encoding can't be written in the file. This is very common in applications that log user provided parameters. We need to allow changing the binnary mode because right now it is impossible to use the built-in log rotation feature when you provide a File object to the LogDevice, and if you provide a filename you can't have binmode. https://github.com/ruby/logger/commit/9114b3ac7e
Diffstat (limited to 'test/logger/test_logger.rb')
-rw-r--r--test/logger/test_logger.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/logger/test_logger.rb b/test/logger/test_logger.rb
index 5806e0c685..029203877a 100644
--- a/test/logger/test_logger.rb
+++ b/test/logger/test_logger.rb
@@ -240,6 +240,29 @@ class TestLogger < Test::Unit::TestCase
assert_equal("false\n", log.msg)
end
+ def test_add_binary_data_with_binmode_logdev
+ EnvUtil.with_default_internal(Encoding::UTF_8) do
+ begin
+ tempfile = Tempfile.new("logger")
+ tempfile.close
+ filename = tempfile.path
+ File.unlink(filename)
+
+ logger = Logger.new filename, binmode: true
+ logger.level = Logger::DEBUG
+
+ str = +"\x80"
+ str.force_encoding("ASCII-8BIT")
+
+ logger.add Logger::DEBUG, str
+ assert_equal(2, File.binread(filename).split(/\n/).size)
+ ensure
+ logger.close
+ tempfile.unlink
+ end
+ end
+ end
+
def test_level_log
logger = Logger.new(nil)
logger.progname = "my_progname"