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
This commit is contained in:
Daniel Martí 2015-09-11 17:41:24 -07:00
parent c0a13ad65f
commit de44771755
9 changed files with 12 additions and 14 deletions

View File

@ -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");

View File

@ -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();
}

View File

@ -58,7 +58,7 @@ public class BonjourFinder extends PeerFinder<BonjourPeer> 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;
}

View File

@ -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);
}
}

View File

@ -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
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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;
}