Skip to content

Redirecting STDERR not working as expected #1082

@MilesRoberts

Description

@MilesRoberts

Trying to redirect STDERR to log, $stderr.puts works, as does warn, but raised errors never make it to the log.

log = File.new('/home/my_user/test_log.log', "w")
$stderr.reopen log
$stderr.puts "writing to log!"
warn "warning!"

require 'some_broken_thing'

log contents in MRI (2.0.0-p0):

/path/to/ruby/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- some_broken_thing (LoadError)
  from /path/to/ruby/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
  from test.rb:5:in `<main>'
writing to log!
warning!

log contents in jruby (1.7.4):

writing to log!
warning!

When I call $stderr.reopen, the error output from the broken require doesn't show up in the console, which is good, but it also never shows up in the file, which isn't so good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions