ruby-changes:47265
From: sonots <ko1@a...>
Date: Fri, 21 Jul 2017 01:47:32 +0900 (JST)
Subject: [ruby-changes:47265] sonots:r59380 (trunk): logger.rb: Fix handling progname
sonots 2017-07-21 01:47:26 +0900 (Fri, 21 Jul 2017) New Revision: 59380 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59380 Log: logger.rb: Fix handling progname Because progname was memoized with ||= a logger call that involved outputting false would be nil. Example code: logger = Logger.new(STDOUT) logger.info(false) # => nil Perform an explicit nil check instead of ||= so that false will be output. patched by Gavin Miller <gavingmiller@g...> [Fix GH-1667] Modified files: trunk/lib/logger.rb trunk/test/logger/test_logger.rb Index: lib/logger.rb =================================================================== --- lib/logger.rb (revision 59379) +++ lib/logger.rb (revision 59380) @@ -457,7 +457,9 @@ class Logger https://github.com/ruby/ruby/blob/trunk/lib/logger.rb#L457 if @logdev.nil? or severity < @level return true end - progname ||= @progname + if progname.nil? + progname = @progname + end if message.nil? if block_given? message = yield Index: test/logger/test_logger.rb =================================================================== --- test/logger/test_logger.rb (revision 59379) +++ test/logger/test_logger.rb (revision 59380) @@ -235,6 +235,10 @@ class TestLogger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/logger/test_logger.rb#L235 log = log_add(logger, WARN, nil, "progname?") assert_equal("progname?\n", log.msg) assert_equal("my_progname", log.progname) + # + logger = Logger.new(nil) + log = log_add(logger, INFO, nil, false) + assert_equal("false\n", log.msg) end def test_level_log -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/