From 875dc31d5a59b14af274836ef5655b5be2c9b66c Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 3 Jan 2010 01:50:32 +0000 Subject: [PATCH] Log message cleanup --- src/com/fsck/k9/MessagingController.java | 8 ++-- src/com/fsck/k9/service/BootReceiver.java | 27 +++++++---- src/com/fsck/k9/service/CoreService.java | 10 ++-- src/com/fsck/k9/service/MailService.java | 57 ++++++++++++++--------- src/com/fsck/k9/service/PollService.java | 18 ++++--- src/com/fsck/k9/service/SleepService.java | 12 ----- 6 files changed, 72 insertions(+), 60 deletions(-) diff --git a/src/com/fsck/k9/MessagingController.java b/src/com/fsck/k9/MessagingController.java index 374a91c99..4a6a62266 100644 --- a/src/com/fsck/k9/MessagingController.java +++ b/src/com/fsck/k9/MessagingController.java @@ -916,10 +916,10 @@ public class MessagingController implements Runnable if (Account.EXPUNGE_ON_POLL.equals(account.getExpungePolicy())) { - if (K9.DEBUG) - { - Log.d(K9.LOG_TAG, "SYNC: Expunging folder " + account.getDescription() + ":" + folder); - } + if (K9.DEBUG) + { + Log.d(K9.LOG_TAG, "SYNC: Expunging folder " + account.getDescription() + ":" + folder); + } remoteFolder.expunge(); } diff --git a/src/com/fsck/k9/service/BootReceiver.java b/src/com/fsck/k9/service/BootReceiver.java index 2060c60f8..1728e5677 100644 --- a/src/com/fsck/k9/service/BootReceiver.java +++ b/src/com/fsck/k9/service/BootReceiver.java @@ -54,7 +54,8 @@ public class BootReceiver extends BroadcastReceiver } else { - Log.w(K9.LOG_TAG, "BootReceiver WakeLock " + wakeLockId + " doesn't exist"); + if (K9.DEBUG) + Log.w(K9.LOG_TAG, "BootReceiver WakeLock " + wakeLockId + " doesn't exist"); } } } @@ -64,7 +65,8 @@ public class BootReceiver extends BroadcastReceiver Integer tmpWakeLockId = getWakeLock(context); try { - Log.i(K9.LOG_TAG, "BootReceiver.onReceive" + intent); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "BootReceiver.onReceive" + intent); if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { @@ -97,7 +99,8 @@ public class BootReceiver extends BroadcastReceiver Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); String alarmedAction = alarmedIntent.getAction(); - Log.i(K9.LOG_TAG, "BootReceiver Got alarm to fire alarmedIntent " + alarmedAction); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "BootReceiver Got alarm to fire alarmedIntent " + alarmedAction); alarmedIntent.putExtra(WAKE_LOCK_ID, tmpWakeLockId); tmpWakeLockId = null; if (alarmedIntent != null) @@ -109,7 +112,8 @@ public class BootReceiver extends BroadcastReceiver { long atTime = intent.getLongExtra(AT_TIME, -1); Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); - Log.i(K9.LOG_TAG,"BootReceiver Scheduling intent " + alarmedIntent + " for " + new Date(atTime)); + if (K9.DEBUG) + Log.i(K9.LOG_TAG,"BootReceiver Scheduling intent " + alarmedIntent + " for " + new Date(atTime)); PendingIntent pi = buildPendingIntent(context, intent); AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); @@ -119,7 +123,8 @@ public class BootReceiver extends BroadcastReceiver else if (CANCEL_INTENT.equals(intent.getAction())) { Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); - Log.i(K9.LOG_TAG, "BootReceiver Canceling alarmedIntent " + alarmedIntent); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "BootReceiver Canceling alarmedIntent " + alarmedIntent); PendingIntent pi = buildPendingIntent(context, intent); @@ -131,7 +136,8 @@ public class BootReceiver extends BroadcastReceiver Integer wakeLockId = intent.getIntExtra(WAKE_LOCK_ID, -1); if (wakeLockId != -1) { - Log.i(K9.LOG_TAG, "BootReceiver Release wakeLock " + wakeLockId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "BootReceiver Release wakeLock " + wakeLockId); releaseWakeLock(wakeLockId); } } @@ -158,7 +164,8 @@ public class BootReceiver extends BroadcastReceiver public static void scheduleIntent(Context context, long atTime, Intent alarmedIntent) { - Log.i(K9.LOG_TAG, "BootReceiver Got request to schedule alarmedIntent " + alarmedIntent.getAction()); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "BootReceiver Got request to schedule alarmedIntent " + alarmedIntent.getAction()); Intent i = new Intent(); i.setClass(context, BootReceiver.class); i.setAction(SCHEDULE_INTENT); @@ -169,7 +176,8 @@ public class BootReceiver extends BroadcastReceiver public static void cancelIntent(Context context, Intent alarmedIntent) { - Log.i(K9.LOG_TAG, "BootReceiver Got request to cancel alarmedIntent " + alarmedIntent.getAction()); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "BootReceiver Got request to cancel alarmedIntent " + alarmedIntent.getAction()); Intent i = new Intent(); i.setClass(context, BootReceiver.class); i.setAction(CANCEL_INTENT); @@ -179,7 +187,8 @@ public class BootReceiver extends BroadcastReceiver public static void releaseWakeLock(Context context, int wakeLockId) { - Log.i(K9.LOG_TAG, "BootReceiver Got request to release wakeLock " + wakeLockId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "BootReceiver Got request to release wakeLock " + wakeLockId); Intent i = new Intent(); i.setClass(context, BootReceiver.class); i.setAction(WAKE_LOCK_RELEASE); diff --git a/src/com/fsck/k9/service/CoreService.java b/src/com/fsck/k9/service/CoreService.java index ed2cb29be..6e1705f38 100644 --- a/src/com/fsck/k9/service/CoreService.java +++ b/src/com/fsck/k9/service/CoreService.java @@ -49,7 +49,8 @@ public abstract class CoreService extends Service wakeLock.setReferenceCounted(false); wakeLock.acquire(K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT); - Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onStart(" + intent + ", " + startId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onStart(" + intent + ", " + startId); int wakeLockId = intent.getIntExtra(BootReceiver.WAKE_LOCK_ID, -1); if (wakeLockId != -1) @@ -60,16 +61,12 @@ public abstract class CoreService extends Service if (coreWakeLockId != null && coreWakeLockId != -1) { if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "Got core wake lock id " + coreWakeLockId); - } WakeLock coreWakeLock = wakeLocks.remove(coreWakeLockId); if (coreWakeLock != null) { if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "Found core wake lock with id " + coreWakeLockId + ", releasing"); - } coreWakeLock.release(); } } @@ -102,7 +99,8 @@ public abstract class CoreService extends Service @Override public void onDestroy() { - Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onDestroy()"); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onDestroy()"); super.onDestroy(); // MessagingController.getInstance(getApplication()).removeListener(mListener); } diff --git a/src/com/fsck/k9/service/MailService.java b/src/com/fsck/k9/service/MailService.java index 5f766a1fc..91bb2171d 100644 --- a/src/com/fsck/k9/service/MailService.java +++ b/src/com/fsck/k9/service/MailService.java @@ -90,7 +90,8 @@ public class MailService extends CoreService public void onCreate() { super.onCreate(); - Log.v(K9.LOG_TAG, "***** MailService *****: onCreate"); + if (K9.DEBUG) + Log.v(K9.LOG_TAG, "***** MailService *****: onCreate"); } @Override @@ -121,13 +122,15 @@ public class MailService extends CoreService } setForeground(true); // if it gets killed once, it'll never restart - Log.i(K9.LOG_TAG, "MailService.onStart(" + intent + ", " + startId - + "), hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "MailService.onStart(" + intent + ", " + startId + + "), hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground); // MessagingController.getInstance(getApplication()).addListener(mListener); if (ACTION_CHECK_MAIL.equals(intent.getAction())) { - Log.i(K9.LOG_TAG, "***** MailService *****: checking mail"); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "***** MailService *****: checking mail"); if (hasConnectivity && doBackground) { @@ -181,7 +184,8 @@ public class MailService extends CoreService notifyConnectionStatus(hasConnectivity); rescheduleAll(hasConnectivity, doBackground, startIdObj); startIdObj = null; - Log.i(K9.LOG_TAG, "Got connectivity action with hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "Got connectivity action with hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground); } else if (CANCEL_CONNECTIVITY_NOTICE.equals(intent.getAction())) { @@ -195,8 +199,8 @@ public class MailService extends CoreService stopSelf(startId); } } - long endTime = System.currentTimeMillis(); - Log.i(K9.LOG_TAG, "MailService.onStart took " + (endTime - startTime) + "ms"); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "MailService.onStart took " + (System.currentTimeMillis() - startTime) + "ms"); } private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId) @@ -246,7 +250,8 @@ public class MailService extends CoreService @Override public void onDestroy() { - Log.v(K9.LOG_TAG, "***** MailService *****: onDestroy()"); + if (K9.DEBUG) + Log.v(K9.LOG_TAG, "***** MailService *****: onDestroy()"); super.onDestroy(); // MessagingController.getInstance(getApplication()).removeListener(mListener); } @@ -278,7 +283,8 @@ public class MailService extends CoreService if (shortestInterval == -1) { - Log.v(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName()); + if (K9.DEBUG) + Log.v(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName()); cancel(); } else @@ -286,15 +292,18 @@ public class MailService extends CoreService long delay = (shortestInterval * (60 * 1000)); long nextTime = System.currentTimeMillis() + delay; - try + if (K9.DEBUG) { - String checkString = "Next check for package " + getApplication().getPackageName() + " scheduled for " + new Date(nextTime); - Log.i(K9.LOG_TAG, checkString); - } - catch (Exception e) - { - // I once got a NullPointerException deep in new Date(); - Log.e(K9.LOG_TAG, "Exception while logging", e); + try + { + Log.i(K9.LOG_TAG, + "Next check for package " + getApplication().getPackageName() + " scheduled for " + new Date(nextTime)); + } + catch (Exception e) + { + // I once got a NullPointerException deep in new Date(); + Log.e(K9.LOG_TAG, "Exception while logging", e); + } } Intent i = new Intent(); @@ -407,10 +416,9 @@ public class MailService extends CoreService if (minInterval != -1) { long nextTime = System.currentTimeMillis() + minInterval; - String checkString = "Next pusher refresh scheduled for " + new Date(nextTime); if (K9.DEBUG) { - Log.d(K9.LOG_TAG, checkString); + Log.d(K9.LOG_TAG, "Next pusher refresh scheduled for " + new Date(nextTime)); } Intent i = new Intent(); i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.MailService"); @@ -428,20 +436,23 @@ public class MailService extends CoreService final WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "K9"); wakeLock.setReferenceCounted(false); wakeLock.acquire(wakeLockTime); - Log.i(K9.LOG_TAG, "MailService queueing Runnable " + runner.hashCode() + " with startId " + startId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "MailService queueing Runnable " + runner.hashCode() + " with startId " + startId); + Runnable myRunner = new Runnable() { public void run() { try { - - Log.i(K9.LOG_TAG, "MailService running Runnable " + runner.hashCode() + " with startId " + startId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "MailService running Runnable " + runner.hashCode() + " with startId " + startId); runner.run(); } finally { - Log.i(K9.LOG_TAG, "MailService completed Runnable " + runner.hashCode() + " with startId " + startId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "MailService completed Runnable " + runner.hashCode() + " with startId " + startId); wakeLock.release(); if (startId != null) { diff --git a/src/com/fsck/k9/service/PollService.java b/src/com/fsck/k9/service/PollService.java index 5376891e8..0d7430a54 100644 --- a/src/com/fsck/k9/service/PollService.java +++ b/src/com/fsck/k9/service/PollService.java @@ -40,13 +40,15 @@ public class PollService extends CoreService { if (START_SERVICE.equals(intent.getAction())) { - Log.i(K9.LOG_TAG, "PollService started with startId = " + startId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "PollService started with startId = " + startId); MessagingController controller = MessagingController.getInstance(getApplication()); Listener listener = (Listener)controller.getCheckMailListener(); if (listener == null) { - Log.i(K9.LOG_TAG, "***** PollService *****: starting new check"); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "***** PollService *****: starting new check"); mListener.setStartId(startId); mListener.wakeLockAcquire(); controller.setCheckMailListener(mListener); @@ -54,14 +56,16 @@ public class PollService extends CoreService } else { - Log.i(K9.LOG_TAG,"***** PollService *****: renewing WakeLock"); + if (K9.DEBUG) + Log.i(K9.LOG_TAG,"***** PollService *****: renewing WakeLock"); listener.setStartId(startId); listener.wakeLockAcquire(); } } else if (STOP_SERVICE.equals(intent.getAction())) { - Log.i(K9.LOG_TAG, "PollService stopping"); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "PollService stopping"); stopSelf(); } @@ -158,7 +162,8 @@ public class PollService extends CoreService controller.setCheckMailListener(null); MailService.rescheduleCheck(PollService.this, null); wakeLockRelease(); - Log.i(K9.LOG_TAG, "PollService stopping with startId = " + startId); + if (K9.DEBUG) + Log.i(K9.LOG_TAG, "PollService stopping with startId = " + startId); stopSelf(startId); } @@ -167,7 +172,8 @@ public class PollService extends CoreService public void checkMailFinished(Context context, Account account) { - Log.v(K9.LOG_TAG, "***** PollService *****: checkMailFinished"); + if (K9.DEBUG) + Log.v(K9.LOG_TAG, "***** PollService *****: checkMailFinished"); try { checkMailDone(context, account); diff --git a/src/com/fsck/k9/service/SleepService.java b/src/com/fsck/k9/service/SleepService.java index 2cc404d96..b0772a73a 100644 --- a/src/com/fsck/k9/service/SleepService.java +++ b/src/com/fsck/k9/service/SleepService.java @@ -26,9 +26,7 @@ public class SleepService extends CoreService { Integer id = latchId.getAndIncrement(); if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "SleepService Preparing CountDownLatch with id = " + id + ", thread " + Thread.currentThread().getName()); - } SleepDatum sleepDatum = new SleepDatum(); CountDownLatch latch = new CountDownLatch(1); sleepDatum.latch = latch; @@ -53,9 +51,7 @@ public class SleepService extends CoreService if (timedOut == false) { if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "SleepService latch timed out for id = " + id + ", thread " + Thread.currentThread().getName()); - } // don't call endSleep here or remove the sleepDatum here, instead of the following block. // We might not get the wakeLock before // falling asleep again, so we have to get the wakeLock *first* The alarmed version will @@ -77,9 +73,7 @@ public class SleepService extends CoreService long endTime = System.currentTimeMillis(); long actualSleep = endTime - startTime; if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "SleepService requested sleep time was " + sleepTime + ", actual was " + actualSleep); - } if (actualSleep < sleepTime) { Log.w(K9.LOG_TAG, "SleepService sleep time too short: requested was " + sleepTime + ", actual was " + actualSleep); @@ -101,9 +95,7 @@ public class SleepService extends CoreService else { if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "SleepService Counting down CountDownLatch with id = " + id); - } latch.countDown(); } reacquireWakeLock(sleepDatum); @@ -111,9 +103,7 @@ public class SleepService extends CoreService else { if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "SleepService Sleep for id " + id + " already finished"); - } } } } @@ -127,9 +117,7 @@ public class SleepService extends CoreService { long timeout = sleepDatum.timeout; if (K9.DEBUG) - { Log.d(K9.LOG_TAG, "SleepService Acquring wakeLock for id for " + timeout + "ms"); - } wakeLock.acquire(timeout); } }