Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept the object that has #to_path in Logger::LogDevice.new #116

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/logger/log_device.rb
Original file line number Diff line number Diff line change
@@ -99,6 +99,7 @@ def fixup_mode(dev, filename)
else
def fixup_mode(dev, filename)
return dev if @binmode
filename = filename.respond_to?(:to_path) ? filename.to_path : filename
dev.autoclose = false
old_dev = dev
dev = File.new(dev.fileno, mode: MODE, path: filename)
15 changes: 15 additions & 0 deletions test/logger/test_logdevice.rb
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
require 'logger'
require 'tempfile'
require 'tmpdir'
require 'pathname'

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

def test_write