Skip to content

Commit

Permalink
logger.rb: Fix handling progname
Browse files Browse the repository at this point in the history
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 93fe0ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/logger/test_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93fe0ff

Please sign in to comment.