From de4477175577cac40e5a05438b7be55a8171e8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 11 Sep 2015 17:41:24 -0700 Subject: [PATCH] Exception logging improvements * On error logs, always print the stack trace * Log full stack traces instead of just exception names or messages * Never use printStackTrace --- F-Droid/src/org/fdroid/fdroid/Utils.java | 2 +- F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java | 2 +- .../org/fdroid/fdroid/localrepo/peers/BonjourFinder.java | 2 +- .../fdroid/fdroid/localrepo/type/BonjourBroadcast.java | 3 +-- .../src/org/fdroid/fdroid/localrepo/type/WifiSwap.java | 3 +-- .../src/org/fdroid/fdroid/net/BluetoothDownloader.java | 2 +- .../org/fdroid/fdroid/net/bluetooth/BluetoothServer.java | 8 ++++---- .../org/fdroid/fdroid/net/bluetooth/httpish/Response.java | 2 +- .../fdroid/fdroid/views/swap/SwapWorkflowActivity.java | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/Utils.java b/F-Droid/src/org/fdroid/fdroid/Utils.java index 7c5005ba9..8edd24575 100644 --- a/F-Droid/src/org/fdroid/fdroid/Utils.java +++ b/F-Droid/src/org/fdroid/fdroid/Utils.java @@ -530,7 +530,7 @@ public final class Utils { return toHexString(mdbytes); } catch (IOException e) { Log.e(TAG, "Error reading \"" + apk.getAbsolutePath() - + "\" to compute " + algo + " hash."); + + "\" to compute " + algo + " hash.", e); return null; } catch (NoSuchAlgorithmException e) { Log.e(TAG, "Device does not support " + algo + " MessageDisgest algorithm"); diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java index f4d3fb751..0512273d6 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java @@ -214,7 +214,7 @@ public class SwapService extends Service { client.execute(host, request); } catch (IOException e) { notifyOfErrorOnUiThread(); - Log.e(TAG, "Error while asking server to swap with us: " + e.getMessage()); + Log.e(TAG, "Error while asking server to swap with us", e); } finally { client.close(); } diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java b/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java index 5c96a8f5c..69a507777 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java @@ -58,7 +58,7 @@ public class BonjourFinder extends PeerFinder implements ServiceLis Log.d(TAG, "Searching for Bonjour (mDNS) clients..."); jmdns = JmDNS.create(InetAddress.getByName(FDroidApp.ipAddressString)); } catch (IOException e) { - e.printStackTrace(); + Log.e(TAG, "", e); } return null; } diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java index ab50642a0..bd29ea26a 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java @@ -63,8 +63,7 @@ public class BonjourBroadcast extends SwapType { setConnected(true); Log.d(TAG, "... Bounjour service started."); } catch (IOException e) { - Log.e(TAG, "Error while registering jmdns service: " + e); - Log.e(TAG, Log.getStackTraceString(e)); + Log.e(TAG, "Error while registering jmdns service", e); setConnected(false); } } diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/type/WifiSwap.java b/F-Droid/src/org/fdroid/fdroid/localrepo/type/WifiSwap.java index ec00bddf9..3409ff939 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/type/WifiSwap.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/type/WifiSwap.java @@ -79,8 +79,7 @@ public class WifiSwap extends SwapType { context.startService(new Intent(context, WifiStateChangeService.class)); } catch (IOException e) { setConnected(false); - Log.e(TAG, "Could not start local repo HTTP server: " + e); - Log.e(TAG, Log.getStackTraceString(e)); + Log.e(TAG, "Could not start local repo HTTP server", e); } Looper.loop(); // start the message receiving loop } diff --git a/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java index c2dcd04ca..b5be71fe4 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java @@ -62,7 +62,7 @@ public class BluetoothDownloader extends Downloader { try { fileDetails = Request.createHEAD(sourceUrl.getPath(), connection).send().toFileDetails(); } catch (IOException e) { - Log.e(TAG, "Error getting file details from Bluetooth \"server\": " + e.getMessage()); + Log.e(TAG, "Error getting file details from Bluetooth \"server\"", e); } } return fileDetails; diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java index 0944ea01d..c5bb6dda4 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java @@ -68,7 +68,7 @@ public class BluetoothServer extends Thread { try { serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid()); } catch (IOException e) { - Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now: " + e.getMessage()); + Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now", e); swap.stop(); isRunning = false; return; @@ -92,7 +92,7 @@ public class BluetoothServer extends Thread { clients.add(client); } } catch (IOException e) { - Log.e(TAG, "Error receiving client connection over Bluetooth server socket, will continue listening for other clients: " + e.getMessage()); + Log.e(TAG, "Error receiving client connection over Bluetooth server socket, will continue listening for other clients", e); } } isRunning = false; @@ -118,7 +118,7 @@ public class BluetoothServer extends Thread { connection = new BluetoothConnection(socket); connection.open(); } catch (IOException e) { - Log.e(TAG, "Error listening for incoming connections over bluetooth - " + e.getMessage()); + Log.e(TAG, "Error listening for incoming connections over bluetooth", e); return; } @@ -129,7 +129,7 @@ public class BluetoothServer extends Thread { Request incomingRequest = Request.listenForRequest(connection); handleRequest(incomingRequest).send(connection); } catch (IOException e) { - Log.e(TAG, "Error receiving incoming connection over bluetooth - " + e.getMessage()); + Log.e(TAG, "Error receiving incoming connection over bluetooth", e); break; } diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java index 835907aa8..1ba8cf9a7 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java @@ -51,7 +51,7 @@ public class Response { } catch (UnsupportedEncodingException e) { // Not quite sure what to do in the case of a phone not supporting UTF-8, so lets // throw a runtime exception and hope that we get good bug reports if this ever happens. - Log.e(TAG, "Device does not support UTF-8: " + e.getMessage()); + Log.e(TAG, "Device does not support UTF-8", e); throw new IllegalStateException("Device does not support UTF-8.", e); } } diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 1746264f1..4e64a8a31 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -715,7 +715,7 @@ public class SwapWorkflowActivity extends AppCompatActivity { broadcast(TYPE_COMPLETE); } catch (Exception e) { broadcast(TYPE_ERROR); - e.printStackTrace(); + Log.e(TAG, "", e); } return null; }