Merge change 21751 into eclair

* changes:
  Make sure we log exceptions in FileLogger
This commit is contained in:
Android (Google) Code Review 2009-08-18 14:07:15 -07:00
commit 2cf87e6c3c
4 changed files with 29 additions and 17 deletions

View File

@ -203,6 +203,12 @@ public abstract class AbstractSyncService implements Runnable {
}
}
public void userLog(Exception e) {
if (Eas.FILE_LOG) {
FileLogger.log(e);
}
}
/**
* Standard logging for EAS.
* If user logging is active, we concatenate any arguments and log them using Log.d

View File

@ -1025,7 +1025,8 @@ public class EasSyncService extends AbstractSyncService {
userLog("Caught IOException: ", ((message == null) ? "" : message));
mExitStatus = EXIT_IO_ERROR;
} catch (Exception e) {
Log.e(TAG, "Uncaught exception in EasSyncService", e);
Log.e(TAG, "Uncaught exception in EasSyncService" + e);
userLog(e);
} finally {
if (!mStop) {
userLog(mMailbox.mDisplayName, ": sync finished");

View File

@ -105,7 +105,7 @@ public abstract class AbstractSyncParser extends Parser {
// Make this a push box through the first sync
// TODO Make frequency conditional on user settings!
mMailbox.mSyncInterval = Mailbox.CHECK_INTERVAL_PUSH;
mService.errorLog("Bad sync key; RESET and delete contacts");
mService.errorLog("Bad sync key; RESET and delete data");
wipe();
// Indicate there's more so that we'll start syncing again
moreAvailable = true;

View File

@ -20,13 +20,13 @@ import android.content.Context;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
public class FileLogger {
private static FileLogger LOGGER = null;
private static FileWriter mLogWriter = null;
public static String LOG_FILE_NAME = "/sdcard/emaillog.txt";
private static Object mLock = new Object();
public synchronized static FileLogger getLogger (Context c) {
LOGGER = new FileLogger();
@ -34,12 +34,10 @@ public class FileLogger {
}
private FileLogger() {
synchronized (mLock) {
try {
mLogWriter = new FileWriter(LOG_FILE_NAME, true);
} catch (IOException e) {
// Doesn't matter
}
try {
mLogWriter = new FileWriter(LOG_FILE_NAME, true);
} catch (IOException e) {
// Doesn't matter
}
}
@ -54,6 +52,15 @@ public class FileLogger {
}
}
static public synchronized void log(Exception e) {
if (mLogWriter != null) {
log("Exception", "Stack trace follows...");
PrintWriter pw = new PrintWriter(mLogWriter);
e.printStackTrace(pw);
pw.flush();
}
}
@SuppressWarnings("deprecation")
static public synchronized void log(String prefix, String str) {
if (LOGGER == null) {
@ -87,14 +94,12 @@ public class FileLogger {
sb.append("\r\n");
String s = sb.toString();
synchronized (mLock) {
if (mLogWriter != null) {
try {
mLogWriter.write(s);
mLogWriter.flush();
} catch (IOException e) {
// Doesn't matter
}
if (mLogWriter != null) {
try {
mLogWriter.write(s);
mLogWriter.flush();
} catch (IOException e) {
// Doesn't matter
}
}
}