1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/logger] Set filename when initializing logger with a File object

This should allow reopen to work.  Requested in ruby issue #14595.

https://github.com/ruby/logger/commit/bd367aff12
This commit is contained in:
Jeremy Evans 2019-05-16 17:35:21 -07:00 committed by Hiroshi SHIBATA
parent 2c22051b4b
commit f4064a0a0c
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 18 additions and 0 deletions

View file

@ -76,6 +76,9 @@ class Logger
def set_dev(log)
if log.respond_to?(:write) and log.respond_to?(:close)
@dev = log
if log.respond_to?(:path)
@filename = log.path
end
else
@dev = open_logfile(log)
@dev.sync = true

View file

@ -60,6 +60,21 @@ class TestLogDevice < Test::Unit::TestCase
ensure
logdev.close
end
# logfile object with path
tempfile = Tempfile.new("logger")
tempfile.sync = true
logdev = d(tempfile)
begin
logdev.write('world')
logfile = File.read(tempfile.path)
assert_equal(1, logfile.split(/\n/).size)
assert_match(/^world$/, logfile)
assert_equal(tempfile.path, logdev.filename)
ensure
logdev.close
File.unlink(tempfile)
tempfile.close(true)
end
end
def test_write