From 8048cd37a562defa2bd78d70531a27ffff17d6dd Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 14 Mar 2022 16:32:18 +0100 Subject: [PATCH] Improved logging --- .../eu/faircode/email/ConnectionHelper.java | 7 +++-- .../java/eu/faircode/email/EmailService.java | 29 ++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ConnectionHelper.java b/app/src/main/java/eu/faircode/email/ConnectionHelper.java index ea695d62a3..3ed98b5092 100644 --- a/app/src/main/java/eu/faircode/email/ConnectionHelper.java +++ b/app/src/main/java/eu/faircode/email/ConnectionHelper.java @@ -556,7 +556,8 @@ public class ConnectionHelper { for (InterfaceAddress iaddr : ni.getInterfaceAddresses()) { InetAddress addr = iaddr.getAddress(); boolean local = (addr.isLoopbackAddress() || addr.isLinkLocalAddress()); - EntityLog.log(context, "Interface=" + ni + " addr=" + addr + " local=" + local); + EntityLog.log(context, EntityLog.Type.Network, + "Interface=" + ni + " addr=" + addr + " local=" + local); if (!local) if (addr instanceof Inet4Address) has4 = true; @@ -581,9 +582,9 @@ public class ConnectionHelper { InetSocketAddress address = new InetSocketAddress(domain, port); SocketFactory factory = SSLSocketFactory.getDefault(); try (SSLSocket sslSocket = (SSLSocket) factory.createSocket()) { - EntityLog.log(context, "Connecting to " + address); + EntityLog.log(context, EntityLog.Type.Network, "Connecting to " + address); sslSocket.connect(address, timeout); - EntityLog.log(context, "Connected " + address); + EntityLog.log(context, EntityLog.Type.Network, "Connected " + address); sslSocket.setSoTimeout(timeout); sslSocket.startHandshake(); diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index b2fc623413..3f3004d796 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -387,7 +387,8 @@ public class EmailService implements AutoCloseable { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Network active = cm.getActiveNetwork(); if (active != null) { - EntityLog.log(context, "Binding to active network " + active); + EntityLog.log(context, EntityLog.Type.Network, "Binding to" + + " active=" + active); properties.put("fairemail.factory", active.getSocketFactory()); } } catch (Throwable ex) { @@ -521,14 +522,14 @@ public class EmailService implements AutoCloseable { String key = "dns." + host; try { main = InetAddress.getByName(host); - EntityLog.log(context, "Resolved " + main); + EntityLog.log(context, EntityLog.Type.Network, "Main address=" + main); prefs.edit().putString(key, main.getHostAddress()).apply(); } catch (UnknownHostException ex) { String last = prefs.getString(key, null); if (TextUtils.isEmpty(last)) throw new MessagingException(ex.getMessage(), ex); else { - EntityLog.log(context, "Using " + key + "=" + last); + EntityLog.log(context, EntityLog.Type.Network, "Using " + key + "=" + last); main = InetAddress.getByName(last); } } @@ -541,7 +542,7 @@ public class EmailService implements AutoCloseable { for (InetAddress iaddr : InetAddress.getAllByName(host)) if (iaddr instanceof Inet4Address) { main = iaddr; - EntityLog.log(context, "Preferring=" + main); + EntityLog.log(context, EntityLog.Type.Network, "Preferring=" + main); break; } } catch (UnknownHostException ex) { @@ -610,8 +611,9 @@ public class EmailService implements AutoCloseable { } if (ioError) { - EntityLog.log(context, "Connect ex=" + - ex.getClass().getName() + ":" + ex.getMessage()); + EntityLog.log(context, EntityLog.Type.Network, "Connect ex=" + + ex.getClass().getName() + ":" + + ex + "\n" + android.util.Log.getStackTraceString(ex)); try { // Some devices resolve IPv6 addresses while not having IPv6 connectivity InetAddress[] iaddrs = InetAddress.getAllByName(host); @@ -620,13 +622,13 @@ public class EmailService implements AutoCloseable { boolean[] has46 = ConnectionHelper.has46(context); - EntityLog.log(context, "Address main=" + main + + EntityLog.log(context, EntityLog.Type.Network, "Address main=" + main + " count=" + iaddrs.length + " ip4=" + ip4 + " max4=" + MAX_IPV4 + " has4=" + has46[0] + " ip6=" + ip6 + " max6=" + MAX_IPV6 + " has6=" + has46[1]); for (InetAddress iaddr : iaddrs) { - EntityLog.log(context, "Address resolved=" + iaddr); + EntityLog.log(context, EntityLog.Type.Network, "Address resolved=" + iaddr); if (iaddr.equals(main)) continue; @@ -644,13 +646,14 @@ public class EmailService implements AutoCloseable { } try { - EntityLog.log(context, "Falling back to " + iaddr); + EntityLog.log(context, EntityLog.Type.Network, "Falling back to " + iaddr); _connect(iaddr, port, require_id, user, factory); return; } catch (MessagingException ex1) { ex = ex1; - EntityLog.log(context, "Fallback ex=" + - ex1.getClass().getName() + ":" + ex1.getMessage()); + EntityLog.log(context, EntityLog.Type.Network, "Fallback ex=" + + ex1.getClass().getName() + ":" + + ex1 + " " + android.util.Log.getStackTraceString(ex1)); } } } catch (IOException ex1) { @@ -665,7 +668,7 @@ public class EmailService implements AutoCloseable { private void _connect( InetAddress address, int port, boolean require_id, String user, SSLSocketFactoryService factory) throws MessagingException { - EntityLog.log(context, "Connecting to " + address + ":" + port); + EntityLog.log(context, EntityLog.Type.Network, "Connecting to " + address + ":" + port); isession = Session.getInstance(properties, authenticator); @@ -724,7 +727,7 @@ public class EmailService implements AutoCloseable { Map crumb = new HashMap<>(); for (String key : sid.keySet()) { crumb.put(key, sid.get(key)); - EntityLog.log(context, "Server " + key + "=" + sid.get(key)); + EntityLog.log(context, EntityLog.Type.Protocol, "Server " + key + "=" + sid.get(key)); } Log.breadcrumb("server", crumb); }