From 1963da73ce7cf5bff19df646967638cfa52b3cb4 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Dec 2021 08:50:59 +0100 Subject: [PATCH] Improved logging --- app/src/main/java/eu/faircode/email/Log.java | 34 +++++++++++--------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index 5973c128e6..966c4f0ea9 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -571,24 +571,28 @@ public class Log { Object v = data.get(key); Object value = v; + int length = -1; if (v != null && v.getClass().isArray()) { - int length = Array.getLength(v); - if (length <= 10) { - String[] elements = new String[length]; - for (int i = 0; i < length; i++) { - Object element = Array.get(v, i); - if (element instanceof Long) - elements[i] = element.toString() + " (0x" + Long.toHexString((Long) element) + ")"; - else - elements[i] = (element == null ? null : printableString(element.toString())); - } - value = TextUtils.join(",", elements); - } else - value = "[" + length + "]"; + length = Array.getLength(v); + String[] elements = new String[Math.min(length, 10)]; + for (int i = 0; i < elements.length; i++) { + Object element = Array.get(v, i); + if (element instanceof Long) + elements[i] = element + " (0x" + Long.toHexString((Long) element) + ")"; + else + elements[i] = (element == null ? "" : printableString(element.toString())); + } + value = TextUtils.join(",", elements); + if (length > 10) + value += ", ..."; + value = "[" + value + "]"; } else if (v instanceof Long) - value = v.toString() + " (0x" + Long.toHexString((Long) v) + ")"; + value = v + " (0x" + Long.toHexString((Long) v) + ")"; + else if (v instanceof Bundle) + value = "{" + TextUtils.join(" ", getExtras((Bundle) v)) + "}"; - result.add(key + "=" + value + (value == null ? "" : " (" + v.getClass().getSimpleName() + ")")); + result.add(key + "=" + value + (value == null ? "" : + " (" + v.getClass().getSimpleName() + (length < 0 ? "" : ":" + length) + ")")); } } catch (BadParcelableException ex) { // android.os.BadParcelableException: ClassNotFoundException when unmarshalling: ...