MCPcopy Create free account
hub / github.com/M66B/FairEmail / attachLog

Method attachLog

app/src/main/java/eu/faircode/email/DebugHelper.java:1277–1327  ·  view source on GitHub ↗
(Context context, long id, int sequence)

Source from the content-addressed store, hash-verified

1275 }
1276
1277 private static void attachLog(Context context, long id, int sequence) {
1278 try {
1279 DB db = DB.getInstance(context);
1280
1281 EntityAttachment attachment = new EntityAttachment();
1282 attachment.message = id;
1283 attachment.sequence = sequence;
1284 attachment.name = "log.txt";
1285 attachment.type = "text/plain";
1286 attachment.disposition = Part.ATTACHMENT;
1287 attachment.size = null;
1288 attachment.progress = 0;
1289 attachment.id = db.attachment().insertAttachment(attachment);
1290
1291 long size = 0;
1292 File file = attachment.getFile(context);
1293 try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
1294 long from = new Date().getTime() - 24 * 3600 * 1000L;
1295 DateFormat TF = Helper.getTimeInstance(context);
1296
1297 for (EntityLog entry : db.log().getLogs(from, null))
1298 if (entry.data != null && entry.data.contains("backoff="))
1299 size += write(os, String.format("%s %s\r\n",
1300 TF.format(entry.time),
1301 entry.data));
1302
1303 size += write(os, "\r\n");
1304
1305 for (EntityLog entry : db.log().getLogs(from, null)) {
1306 size += write(os, String.format("%s [%d:%d:%d:%d:%d] %s\r\n",
1307 TF.format(entry.time),
1308 entry.type.ordinal(),
1309 (entry.thread == null ? 0 : entry.thread),
1310 (entry.account == null ? 0 : entry.account),
1311 (entry.folder == null ? 0 : entry.folder),
1312 (entry.message == null ? 0 : entry.message),
1313 entry.data));
1314 if (size > MAX_LOG_SIZE) {
1315 size += write(os, "<truncated>\r\n");
1316 break;
1317 }
1318 }
1319 }
1320
1321 db.attachment().setDownloaded(attachment.id, size);
1322 if (!BuildConfig.DEBUG && size > MIN_ZIP_SIZE)
1323 attachment.zip(context);
1324 } catch (Throwable ex) {
1325 Log.e(ex);
1326 }
1327 }
1328
1329 private static void attachOperations(Context context, long id, int sequence) {
1330 try {

Callers 1

getDebugInfoMethod · 0.95

Calls 13

getInstanceMethod · 0.95
attachmentMethod · 0.95
getFileMethod · 0.95
getTimeInstanceMethod · 0.95
logMethod · 0.95
writeMethod · 0.95
zipMethod · 0.95
eMethod · 0.95
insertAttachmentMethod · 0.80
getLogsMethod · 0.80
setDownloadedMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected