Issue #14141 has been updated by sorah (Sorah Fukumori).


At least that satisfies my need. I think advanced error logging can be achieved by existing Exception#{class,message,backtrace}.


----------------------------------------
Feature #14141: Exception#display to display same formatted text for IO
https://bugs.ruby-lang.org/issues/14141#change-68044

* Author: sorah (Sorah Fukumori)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Most people want to log caught exceptions to stderr (or somewhere else) then continues their program as usual.

```
def the_program
  # ...
  raise "failure!"
  # ...
rescue RuntimeError => e
  $stderr.puts "#{e.message} (#{e.class})\n\t#{e.backtrace.join("\n\t")}"
  retry
end
```

I'm very bored to write error logging many time...
I want to log errors in the default format of Ruby, just like the following:

```
rescue RuntimeError => e
  e.display
  # ...
```

From Ruby 2.5, we've started branching error formatting on TTY-ness of `$stderr`. It'd be bit more useful if we can log using the same format with the format which Ruby determines.

Ruby already has `Object#display`. 
One consideration is to retrieve formatted String from Exception object, but the current error logging code (eval_error.c) depends on IO,
so I want to start from just having `Exception#display`.  I think most use case is just to log errors into IO.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>