Permalink
Browse files

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@gmail.com> [Fix GH-1667]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
sonots committed Jul 20, 2017
1 parent 1da6483 commit 93fe0ff2f1a2818523799d3da68cade115bec783
Showing with 7 additions and 1 deletion.
  1. +3 −1 lib/logger.rb
  2. +4 −0 test/logger/test_logger.rb
View
@@ -457,7 +457,9 @@ def add(severity, message = nil, progname = nil)
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
@@ -235,6 +235,10 @@ def test_add
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

0 comments on commit 93fe0ff

Please sign in to comment.