Skip to content

Commit 39a69fb

Browse files
committed
handle JRuby separately
1 parent abf48a6 commit 39a69fb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/logging/appenders/console.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def reopen
3939
@mutex.synchronize {
4040
if defined? @io && @io
4141
flush
42-
@io.close rescue nil
42+
# JRuby will close the underlying file descriptor, so we don't want to
43+
# do that even though this is a copy of STDOUT / STDERR
44+
if !defined?(JRUBY_VERSION)
45+
@io.close rescue nil
46+
end
4347
end
4448
@io = open_fd
4549
}

lib/logging/appenders/io.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,16 @@ def close( *args )
4848
super
4949

5050
io, @io = @io, nil
51-
unless [STDIN, STDERR, STDOUT].include?(io)
52-
io.send(@close_method) if @close_method && io.respond_to?(@close_method)
51+
52+
# JRuby will always close the underlying file descriptor, so we need to
53+
# check the FD number and not just the Ruby object ID
54+
close_io = if defined?(JRUBY_VERSION)
55+
![STDIN.fileno, STDERR.fileno, STDOUT.fileno].include?(io.fileno)
56+
else
57+
![STDIN, STDERR, STDOUT].include?(io)
5358
end
59+
60+
io.send(@close_method) if close_io && @close_method && io.respond_to?(@close_method)
5461
rescue IOError
5562
ensure
5663
return self

0 commit comments

Comments
 (0)