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:
parent
2c22051b4b
commit
f4064a0a0c
2 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue