plant DebugTree if K9.DEBUG || BuildConfig.DEBUG

This commit is contained in:
Vincent Breitmoser 2017-03-02 20:15:00 +01:00
parent 021b24c93f
commit 05bd6e0a5b
15 changed files with 41 additions and 29 deletions

View file

@ -137,7 +137,7 @@ public class K9 extends Application {
* Log.d, including protocol dumps.
* Controlled by Preferences at run-time
*/
public static boolean DEBUG = false;
private static boolean DEBUG = false;
/**
* If this is enabled than logging that normally hides sensitive information
@ -523,10 +523,6 @@ public class K9 extends Application {
app = this;
Globals.setContext(this);
if (BuildConfig.DEBUG) {
Timber.plant(new DebugTree());
}
K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() {
@Override public boolean enabled() {
return DEBUG;
@ -675,7 +671,7 @@ public class K9 extends Application {
*/
public static void loadPrefs(Preferences prefs) {
Storage storage = prefs.getStorage();
DEBUG = storage.getBoolean("enableDebugLogging", BuildConfig.DEVELOPER_MODE);
setDebug(storage.getBoolean("enableDebugLogging", BuildConfig.DEVELOPER_MODE));
DEBUG_SENSITIVE = storage.getBoolean("enableSensitiveLogging", false);
mAnimations = storage.getBoolean("animations", true);
mGesturesEnabled = storage.getBoolean("gesturesEnabled", false);
@ -1020,7 +1016,14 @@ public class K9 extends Application {
return false;
}
public static void setDebug(boolean debug) {
K9.DEBUG = debug;
updateLoggingStatus();
}
public static boolean isDebug() {
return DEBUG;
}
public static boolean startIntegratedInbox() {
return mStartIntegratedInbox;
@ -1422,4 +1425,13 @@ public class K9 extends Application {
editor.commit();
}
}
private static void updateLoggingStatus() {
Timber.uprootAll();
boolean enableDebugLogging = BuildConfig.DEBUG || DEBUG;
if (enableDebugLogging) {
Timber.plant(new DebugTree());
}
}
}

View file

@ -45,7 +45,7 @@ public class ActivityListener extends SimpleMessagingListener {
return context.getString(R.string.status_next_poll,
DateUtils.getRelativeTimeSpanString(nextPollTime, System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS, 0));
} else if (K9.DEBUG && MailService.isSyncDisabled()) {
} else if (K9.isDebug() && MailService.isSyncDisabled()) {
if (MailService.hasNoConnectivity()) {
return context.getString(R.string.status_no_network);
} else if (MailService.isSyncNoBackground()) {

View file

@ -357,7 +357,7 @@ public class Prefs extends K9PreferenceActivity {
mHideUserAgent = (CheckBoxPreference)findPreference(PREFERENCE_HIDE_USERAGENT);
mHideTimeZone = (CheckBoxPreference)findPreference(PREFERENCE_HIDE_TIMEZONE);
mDebugLogging.setChecked(K9.DEBUG);
mDebugLogging.setChecked(K9.isDebug());
mSensitiveLogging.setChecked(K9.DEBUG_SENSITIVE);
mHideUserAgent.setChecked(K9.hideUserAgent());
mHideTimeZone.setChecked(K9.hideTimeZone());
@ -529,10 +529,10 @@ public class Prefs extends K9PreferenceActivity {
K9.setAttachmentDefaultPath(mAttachmentPathPreference.getSummary().toString());
boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue());
if (!K9.DEBUG && mDebugLogging.isChecked()) {
if (!K9.isDebug() && mDebugLogging.isChecked()) {
Toast.makeText(this, R.string.debug_logging_enabled, Toast.LENGTH_LONG).show();
}
K9.DEBUG = mDebugLogging.isChecked();
K9.setDebug(mDebugLogging.isChecked());
K9.DEBUG_SENSITIVE = mSensitiveLogging.isChecked();
K9.setHideUserAgent(mHideUserAgent.isChecked());
K9.setHideTimeZone(mHideTimeZone.isChecked());

View file

@ -1287,7 +1287,7 @@ public class MessagingController {
public void messageFinished(T message, int number, int ofTotal) {
try {
if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate)) {
if (K9.DEBUG) {
if (K9.isDebug()) {
if (message.isSet(Flag.DELETED)) {
Timber.v("Newly downloaded message %s:%s:%s was marked deleted on server, " +
"skipping", account, folder, message.getUid());
@ -2146,7 +2146,7 @@ public class MessagingController {
private static AtomicBoolean loopCatch = new AtomicBoolean();
private void addErrorMessage(Account account, String subject, String body) {
if (!K9.DEBUG) {
if (!K9.isDebug()) {
return;
}
if (!loopCatch.compareAndSet(false, true)) {

View file

@ -1873,7 +1873,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
String messagePartId = cursor.getString(0);
File file = localStore.getAttachmentFile(messagePartId);
if (file.exists()) {
if (!file.delete() && K9.DEBUG) {
if (!file.delete() && K9.isDebug()) {
Timber.d("Couldn't delete message part file: %s", file.getAbsolutePath());
}
}

View file

@ -301,7 +301,7 @@ public class LocalStore extends Store implements Serializable {
}
public void compact() throws MessagingException {
if (K9.DEBUG) {
if (K9.isDebug()) {
Timber.i("Before compaction size = %d", getSize());
}
@ -313,20 +313,20 @@ public class LocalStore extends Store implements Serializable {
}
});
if (K9.DEBUG) {
if (K9.isDebug()) {
Timber.i("After compaction size = %d", getSize());
}
}
public void clear() throws MessagingException {
if (K9.DEBUG) {
if (K9.isDebug()) {
Timber.i("Before prune size = %d", getSize());
}
deleteAllMessageDataFromDisk();
if (K9.DEBUG) {
if (K9.isDebug()) {
Timber.i("After prune / before compaction size = %d", getSize());
Timber.i("Before clear folder count = %d", getFolderCount());
Timber.i("Before clear message count = %d", getMessageCount());
@ -352,7 +352,7 @@ public class LocalStore extends Store implements Serializable {
compact();
if (K9.DEBUG) {
if (K9.isDebug()) {
Timber.i("After clear message count = %d", getMessageCount());
Timber.i("After clear size = %d", getSize());
}

View file

@ -265,7 +265,7 @@ public class LockableDatabase {
lockRead();
final boolean doTransaction = transactional && inTransaction.get() == null;
try {
final boolean debug = K9.DEBUG;
final boolean debug = K9.isDebug();
if (doTransaction) {
inTransaction.set(Boolean.TRUE);
mDb.beginTransaction();

View file

@ -47,7 +47,7 @@ class TextBodyBuilder {
if (mIncludeQuotedText) {
InsertableHtmlContent quotedHtmlContent = getQuotedTextHtml();
if (K9.DEBUG) {
if (K9.isDebug()) {
Timber.d("insertable: %s", quotedHtmlContent.toDebugString());
}

View file

@ -166,7 +166,7 @@ public class Settings {
T defaultValue = setting.getDefaultValue();
validatedSettingsMutable.put(settingName, defaultValue);
if (K9.DEBUG) {
if (K9.isDebug()) {
String prettyValue = setting.toPrettyString(defaultValue);
Timber.v("Added new setting \"%s\" with default value \"%s\"", settingName, prettyValue);
}

View file

@ -609,7 +609,7 @@ public class SettingsImporter {
* The new value for the preference.
*/
private static void putString(StorageEditor editor, String key, String value) {
if (K9.DEBUG) {
if (K9.isDebug()) {
String outputValue = value;
if (!K9.DEBUG_SENSITIVE && (key.endsWith(".transportUri") || key.endsWith(".storeUri"))) {
outputValue = "*sensitive*";

View file

@ -106,7 +106,7 @@ public class AttachmentTempFileProvider extends FileProvider {
allFilesDeleted = false;
}
} else {
if (K9.DEBUG) {
if (K9.isDebug()) {
String timeLeftStr = String.format(
Locale.ENGLISH, "%.2f", (lastModified - deletionThreshold) / 1000 / 60.0);
Timber.e("Not deleting temp file (for another %s minutes)", timeLeftStr);

View file

@ -85,7 +85,7 @@ public class DecryptedFileProvider extends FileProvider {
allFilesDeleted = false;
}
} else {
if (K9.DEBUG) {
if (K9.isDebug()) {
String timeLeftStr = String.format(
Locale.ENGLISH, "%.2f", (lastModified - deletionThreshold) / 1000 / 60.0);
Timber.e("Not deleting temp file (for another %s minutes)", timeLeftStr);

View file

@ -75,7 +75,7 @@ public class ActivityListenerTest {
String operation = activityListener.getOperation(context);
if (K9.DEBUG) {
if (K9.isDebug()) {
assertEquals("Polling and pushing disabled", operation);
} else {
assertEquals("Syncing disabled", operation);
@ -90,7 +90,7 @@ public class ActivityListenerTest {
String operation = activityListener.getOperation(context);
if (K9.DEBUG) {
if (K9.isDebug()) {
assertEquals("Polling and pushing disabled", operation);
} else {
assertEquals("Syncing disabled", operation);
@ -104,7 +104,7 @@ public class ActivityListenerTest {
String operation = activityListener.getOperation(context);
if (K9.DEBUG) {
if (K9.isDebug()) {
assertEquals("Polling and pushing disabled", operation);
} else {
assertEquals("Syncing disabled", operation);

View file

@ -183,7 +183,7 @@ public class MessagingControllerTest {
@Test()
public void clearFolderSynchronous_whenExceptionThrown_shouldAddErrorMessageInDebug() throws MessagingException {
if (K9.DEBUG) {
if (K9.isDebug()) {
doThrow(new RuntimeException("Test")).when(localFolder).open(Folder.OPEN_MODE_RW);
controller.clearFolderSynchronous(account, FOLDER_NAME, listener);

View file

@ -42,7 +42,7 @@ public class MigrationTest {
@Before
public void setUp() throws Exception {
K9.DEBUG = true;
K9.setDebug(true);
ShadowLog.stream = System.out;
ShadowSQLiteConnection.reset();