Navigation Menu

Skip to content

Commit

Permalink
Added error handling to onThrowable() to protect against exceptions i…
Browse files Browse the repository at this point in the history
…n error handler. Added enable() method to DebugLogConfig()
  • Loading branch information
ollie72 committed Jun 10, 2011
1 parent 9ba6ee9 commit 8f4f42d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
22 changes: 22 additions & 0 deletions RESTProvider/src/novoda/rest/logging/DebugLogConfig.java
Expand Up @@ -17,6 +17,7 @@

package novoda.rest.logging;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Handler;
Expand Down Expand Up @@ -98,4 +99,25 @@ public DebugLogConfig(InputStream config) {
activeHandler.setLevel(Level.ALL);
rootLogger.addHandler(activeHandler);
}

/**
* Enables logging
*
*/
public static void enable() {
try {
String config = "org.apache.http.impl.conn.level = FINEST\n"
+ "org.apache.http.impl.client.level = FINEST\n"
+ "org.apache.http.client.level = FINEST\n" + "org.apache.http.level = FINEST";
InputStream in = new ByteArrayInputStream(config.getBytes());
LogManager.getLogManager().readConfiguration(in);
} catch (IOException e) {
Log.w(DebugLogConfig.class.getSimpleName(), "Can't read configuration file for logging");
}
Logger rootLogger = LogManager.getLogManager().getLogger("");
activeHandler = new DalvikLogHandler();
activeHandler.setLevel(Level.ALL);
rootLogger.addHandler(activeHandler);
}

}
34 changes: 21 additions & 13 deletions RESTProvider/src/novoda/rest/services/HttpService.java
Expand Up @@ -116,19 +116,27 @@ protected void onHandleIntent(Intent intent) {
}

protected void onThrowable(Exception e) {
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "an error occured against intent: " + intent);
Log.e(TAG, e.getMessage() + "");
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.e(TAG, "full stack trace:", e);
}

if (receiver != null) {
final Bundle bundle = new Bundle();
bundle.putString(Intent.EXTRA_TEXT, e.toString());
receiver.send(STATUS_ERROR, bundle);
}
try
{
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "an error occured against intent: " + intent);
Log.e(TAG, e.getMessage() + "");
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.e(TAG, "full stack trace:", e);
}

if (receiver != null) {
final Bundle bundle = new Bundle();
bundle.putString(Intent.EXTRA_TEXT, e.toString());
receiver.send(STATUS_ERROR, bundle);
}
}
catch (Exception error)
{
// Exception thrown in exception handling code - ouch
Log.e("TasteCard", "Exception in onThrowable exception handler");
}
}

protected HttpUriRequest getHttpUriRequest(Intent intent) {
Expand Down

0 comments on commit 8f4f42d

Please sign in to comment.