Prevent crash

pull/169/head
M66B 6 years ago
parent eaa2196716
commit bcf7ca3ae4

@ -123,7 +123,8 @@ public class Log {
} }
public static int e(String msg) { public static int e(String msg) {
if (BuildConfig.BETA_RELEASE) { if (BuildConfig.BETA_RELEASE)
try {
List<StackTraceElement> ss = new ArrayList<>(Arrays.asList(new Throwable().getStackTrace())); List<StackTraceElement> ss = new ArrayList<>(Arrays.asList(new Throwable().getStackTrace()));
ss.remove(0); ss.remove(0);
Bugsnag.notify("Internal error", msg, ss.toArray(new StackTraceElement[0]), new Callback() { Bugsnag.notify("Internal error", msg, ss.toArray(new StackTraceElement[0]), new Callback() {
@ -132,6 +133,8 @@ public class Log {
report.getError().setSeverity(Severity.ERROR); report.getError().setSeverity(Severity.ERROR);
} }
}); });
} catch (Throwable ex) {
ex.printStackTrace();
} }
return android.util.Log.e(TAG, msg); return android.util.Log.e(TAG, msg);
} }
@ -142,37 +145,61 @@ public class Log {
public static int w(Throwable ex) { public static int w(Throwable ex) {
if (BuildConfig.BETA_RELEASE) if (BuildConfig.BETA_RELEASE)
try {
Bugsnag.notify(ex, Severity.INFO); Bugsnag.notify(ex, Severity.INFO);
} catch (Throwable ex1) {
ex1.printStackTrace();
}
return android.util.Log.w(TAG, ex + "\n" + android.util.Log.getStackTraceString(ex)); return android.util.Log.w(TAG, ex + "\n" + android.util.Log.getStackTraceString(ex));
} }
public static int e(Throwable ex) { public static int e(Throwable ex) {
if (BuildConfig.BETA_RELEASE) if (BuildConfig.BETA_RELEASE)
try {
Bugsnag.notify(ex, Severity.WARNING); Bugsnag.notify(ex, Severity.WARNING);
} catch (Throwable ex1) {
ex1.printStackTrace();
}
return android.util.Log.e(TAG, ex + "\n" + android.util.Log.getStackTraceString(ex)); return android.util.Log.e(TAG, ex + "\n" + android.util.Log.getStackTraceString(ex));
} }
public static int w(String prefix, Throwable ex) { public static int w(String prefix, Throwable ex) {
if (BuildConfig.BETA_RELEASE) if (BuildConfig.BETA_RELEASE)
try {
Bugsnag.notify(ex, Severity.INFO); Bugsnag.notify(ex, Severity.INFO);
} catch (Throwable ex1) {
ex1.printStackTrace();
}
return android.util.Log.w(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex)); return android.util.Log.w(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex));
} }
public static int e(String prefix, Throwable ex) { public static int e(String prefix, Throwable ex) {
if (BuildConfig.BETA_RELEASE) if (BuildConfig.BETA_RELEASE)
try {
Bugsnag.notify(ex, Severity.WARNING); Bugsnag.notify(ex, Severity.WARNING);
} catch (Throwable ex1) {
ex1.printStackTrace();
}
return android.util.Log.e(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex)); return android.util.Log.e(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex));
} }
static void setCrashReporting(boolean enabled) { static void setCrashReporting(boolean enabled) {
try {
if (enabled) if (enabled)
Bugsnag.startSession(); Bugsnag.startSession();
else else
Bugsnag.stopSession(); Bugsnag.stopSession();
} catch (Throwable ex) {
ex.printStackTrace();
}
} }
static void breadcrumb(String name, Map<String, String> crumb) { static void breadcrumb(String name, Map<String, String> crumb) {
try {
Bugsnag.leaveBreadcrumb(name, BreadcrumbType.LOG, crumb); Bugsnag.leaveBreadcrumb(name, BreadcrumbType.LOG, crumb);
} catch (Throwable ex) {
ex.printStackTrace();
}
} }
static void setupBugsnag(Context context) { static void setupBugsnag(Context context) {

Loading…
Cancel
Save