From 8be1db079e8a5c3e6db8d573cb5259a8ea73102b Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 14 Dec 2023 18:51:32 +0100 Subject: [PATCH] Small improvement --- app/src/main/java/eu/faircode/email/ActivityView.java | 4 ++-- app/src/main/java/eu/faircode/email/Log.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 84c1d14cdf..574d36c348 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -1502,7 +1502,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB new SimpleTask() { @Override protected Long onExecute(Context context, Bundle args) throws Throwable { - File file = new File(context.getFilesDir(), "crash.log"); + File file = new File(context.getFilesDir(), Log.CRASH_LOG_NAME); if (file.exists()) { StringBuilder sb = new StringBuilder(); try { @@ -1535,7 +1535,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB ToastEx.makeText(ActivityView.this, Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show(); } - }.execute(this, new Bundle(), "crash:log"); + }.execute(this, new Bundle(), Log.CRASH_LOG_NAME); } private void checkUpdate(boolean always) { diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index 2173fafbeb..1e268900a6 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -195,6 +195,8 @@ import javax.net.ssl.X509TrustManager; public class Log { private static Context ctx; + static final String CRASH_LOG_NAME = "crash.log"; + private static final long MAX_LOG_SIZE = 8 * 1024 * 1024L; private static final int MAX_CRASH_REPORTS = (BuildConfig.TEST_RELEASE ? 50 : 5); private static final long MIN_FILE_SIZE = 1024 * 1024L; @@ -1844,12 +1846,14 @@ public class Log { } static void writeCrashLog(Context context, Throwable ex) { - File file = new File(context.getFilesDir(), "crash.log"); + File file = new File(context.getFilesDir(), CRASH_LOG_NAME); Log.w("Writing exception to " + file); try (FileWriter out = new FileWriter(file, true)) { out.write(BuildConfig.VERSION_NAME + BuildConfig.REVISION + " " + new Date() + "\r\n"); - out.write(ex + "\r\n" + new ThrowableWrapper(ex).getSafeStackTraceString() + "\r\n"); + ThrowableWrapper w = new ThrowableWrapper(ex); + out.write(w.toSafeString() + "\r\n"); + out.write(w.getSafeStackTraceString() + "\r\n"); } catch (IOException e) { Log.e(e); }