@@ -51,6 +51,9 @@ public static void e(String msg, Object... args) {
5151 }
5252
5353 public static void e (String msg , Throwable throwable ) {
54+ if (exceptionListener != null ) {
55+ exceptionListener .onException (throwable );
56+ }
5457 if (msg != null && msg .contains ("%s" )) {
5558 log (LogType .ERROR , msg , getStackTraceString (throwable ));
5659 } else {
@@ -71,6 +74,9 @@ public static void d(String msg, Object... args) {
7174 * @param throwable to log
7275 */
7376 public static void exception (Throwable throwable ) {
77+ if (exceptionListener != null ) {
78+ exceptionListener .onException (throwable );
79+ }
7480 ExceptionHandler .getInstance ().reportException (throwable );
7581
7682 if (throwable instanceof OutOfMemoryError ) {
@@ -222,4 +228,19 @@ public static class Level {
222228 */
223229 public static final int DEBUG = 3 ;
224230 }
231+
232+ public interface ExceptionListener {
233+ void onException (Throwable t );
234+ }
235+
236+ private static ExceptionListener exceptionListener ;
237+
238+ /**
239+ * Sets listener for all logged exceptions.
240+ *
241+ * @param listener The listener that will receive all logged exceptions.
242+ */
243+ public static void setExceptionListener (ExceptionListener listener ) {
244+ exceptionListener = listener ;
245+ }
225246}
0 commit comments