import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.StreamHandler;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String args[]) {
Logger log = Logger.getAnonymousLogger();
setLoggerhandler(log);
log.finest(new Exception().toString());
}
public static void setLoggerhandler(Logger logger) {
Handler handler = new ExceptionHandler();
logger.addHandler(handler);
logger.setLevel(Level.ALL);
}
}
class ExceptionHandler extends StreamHandler {
public void publish(LogRecord record) {
String msg = record.getMessage();
int exceptionIndex = msg.indexOf("Exception");
if (exceptionIndex > -1) {
Pattern pattern = Pattern.compile("(.*Exception.*)");
Matcher matcher = pattern.matcher(msg);
if (matcher != null && matcher.find()) {
String err = "EXCEPTION FOUND " + matcher.group(1);
System.out.println(err);
}
}
}
}