diff --git a/lib/logger/log_device.rb b/lib/logger/log_device.rb index d287a470fc..c6dc43c11a 100644 --- a/lib/logger/log_device.rb +++ b/lib/logger/log_device.rb @@ -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 diff --git a/test/logger/test_logdevice.rb b/test/logger/test_logdevice.rb index 30047f89b1..72802f690d 100644 --- a/test/logger/test_logdevice.rb +++ b/test/logger/test_logdevice.rb @@ -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