[前][次][番号順一覧][スレッド一覧]

ruby-changes:61672

From: Lourens <ko1@a...>
Date: Thu, 11 Jun 2020 14:23:57 +0900 (JST)
Subject: [ruby-changes:61672] f3e12caa08 (master): [ruby/logger] Let File::NULL ("/dev/null", "NUL" etc.) be considered a nil log device

https://git.ruby-lang.org/ruby.git/commit/?id=f3e12caa08

From f3e12caa088cc893a54bc2810ff511e4c89b322b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lourens=20Naud=C3=A9?= <lourens@b...>
Date: Sat, 28 Mar 2020 16:11:41 +0000
Subject: [ruby/logger] Let File::NULL ("/dev/null", "NUL" etc.) be considered
 a nil log device

https://github.com/ruby/logger/commit/b42a1b99aa

diff --git a/lib/logger.rb b/lib/logger.rb
index f0b99f7..4000dae 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -385,7 +385,7 @@ class Logger https://github.com/ruby/ruby/blob/trunk/lib/logger.rb#L385
     self.datetime_format = datetime_format
     self.formatter = formatter
     @logdev = nil
-    if logdev
+    if logdev && logdev != File::NULL
       @logdev = LogDevice.new(logdev, shift_age: shift_age,
         shift_size: shift_size,
         shift_period_suffix: shift_period_suffix,
diff --git a/test/logger/test_logger.rb b/test/logger/test_logger.rb
index 521b562..f8cc2e5 100644
--- a/test/logger/test_logger.rb
+++ b/test/logger/test_logger.rb
@@ -378,4 +378,9 @@ class TestLogger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/logger/test_logger.rb#L378
     log = log(logger, :debug) { "msg" }
     assert_nil log.msg
   end
+
+  def test_does_not_instantiate_log_device_for_File_NULL
+    l = Logger.new(File::NULL)
+    assert_nil(l.instance_variable_get(:@logdev))
+  end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]