From 18600969377c3fbcd7df4fe4e2e04a7960dc5748 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 14 Jun 2022 07:51:57 +0200 Subject: [PATCH] Debug info: limit log.txt size --- app/src/main/java/eu/faircode/email/Log.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index 5c571b39aa..b6c91b1ac7 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -163,6 +163,7 @@ public class Log { private static Context ctx; private static int level = android.util.Log.INFO; + 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 String TAG = "fairemail"; @@ -2435,7 +2436,7 @@ public class Log { long from = new Date().getTime() - 24 * 3600 * 1000L; DateFormat TF = Helper.getTimeInstance(context); - for (EntityLog entry : db.log().getLogs(from, null)) + for (EntityLog entry : db.log().getLogs(from, null)) { size += write(os, String.format("%s [%d:%d:%d:%d] %s\r\n", TF.format(entry.time), entry.type.ordinal(), @@ -2443,6 +2444,11 @@ public class Log { (entry.folder == null ? 0 : entry.folder), (entry.message == null ? 0 : entry.message), entry.data)); + if (size > MAX_LOG_SIZE) { + size += write(os, "\r\n"); + break; + } + } } db.attachment().setDownloaded(attachment.id, size);