elastic / logstash

Logstash - transport and process your logs, events, or other data
https://www.elastic.co/products/logstash
Other
14.18k stars 3.49k forks source link

unified and reliable exception logging experience #12886

Open kares opened 3 years ago

kares commented 3 years ago

Logstash has been a mix of Java and Ruby for a while now.

When exceptions happen logging the proper message/trace usually boils down to plugins, which do not have an easy unified way of doing things.

The LogStash::Logger (Log4J2 wrapper) exposes a logger.error("msg", { 'some' => 'context' }) interface, but otherwise has no special support in logging Ruby errors or Java exceptions.

A loosely followed plugin convention has been to so something like: logger.error("Error occured", :message => e.message, :exception => e.class, :backtrace => e.backtrace)

Would be nice if this got unified w Java logging (logger.error(String, Throwable)) which always includes the cause chain. Either by converting Ruby exceptions to their e.toThrowable() companions or introducing a convention to extract and log causes. The details should be hidden behind a new facade that accepts Java throwables and Ruby rescued errors.

* Please note that org.jruby.RubyException#toThrowable() does not link up causes for the wrapping Java throwable in JRuby 9.2 (this has changed in JRuby 9.3 where the cause chain is mirrored on the throwable)


Additional API desired feature - being able to retrieve a LogStash::Logger given a name e.g. get_logger(name). Would also be nice to have this exposed in an adapter gem, if possible.


relates to: https://github.com/elastic/logstash/issues/11755

kares commented 2 years ago

existing patch-y work-arounds to log Java causes: