Skip to content

Commit d62b6cb

Browse files
committed
Add exception listener to Log class (#481)
1 parent ccac39d commit d62b6cb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ public void response(JSONObject response) {
754754
request.onError(new Request.ErrorCallback() {
755755
@Override
756756
public void error(Exception e) {
757-
Log.i("Failed to receive start response");
757+
Log.e("Failed to receive start response", e);
758758
handleStartResponse(null);
759759
}
760760
});

AndroidSDKCore/src/main/java/com/leanplum/internal/Log.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)