First you need to get all the exception instances that were thrown from / inside your thread (maybe try / catch or Thread.UncoughtExceptionHandler or ThreadPoolExecutor.afterExecute(Runnable r, Throwable t) ).
Then, as soon as you have an exception instance, you can simply register it with log4j, but configure Log4j applications to send exception messages to multiple destinations. Depending on your requirement, you can use file types, Consoles, JDBC, JMS, etc. It is also best to wrap them in an Async application.
Refer - https://logging.apache.org/log4j/2.x/manual/appenders.html
About pushing an exception message into the graphical interface can be implemented in various ways, depending on which technical stack you are using in your application. In our application, we store message events (only critical) in a database, which are then selected by the event monitoring flows from the server and then returned to the graphical interface (JQuery, JavaScript) using http://cometd.org/documentation/cometd-java .
hemant1900
source share