when Ruby exception bubble into Java they are wrapped in instances of
RaiseException, a subclass of RuntimeException. The constructor of
RaiseException takes a RubyException so they should do the job:
It occurred to me that Ruby loggers don’t have the same error printing
features of SLF4J, so I think I am heading the route of using a utility
method to do that and just use error(String) for both cases.
Thanks,
Ariel
Sent from my mobile device. Please excuse any errors.
you can still emulate ~ wrapping … if you’ve looked at the linked
RaiseException.java there’s a constructor that takes a RubyException :
begin
raise “error”
rescue => e
t = org.jruby.exceptions.RaiseException.new(e)
logger.error(“This doesn’t … but will !”, t)
end
although this might not be ideal, I would consider adding a “Ruby”
logging
method (on each level) to the logger’s class that would format errors
with
their back-traces
btw. if you haven’t already written all your slf4j-integration code I
built
a Ruby Logger to SLF4J bridge a few months ago:
it doesn’t have any exception logging feature though, since, as you say,
Ruby’s Logger doesn’t have it. Maybe it wouldn’t be a bad feature to
pass
Ruby exceptions to SLF4J if you pass an exception object instead of a
string as message.