Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 05df114e authored by Vincent Breitmoser's avatar Vincent Breitmoser Committed by GitHub
Browse files

Merge pull request #2309 from k9mail/log-timber

Use Timber for Logging
parents 703b6532 05bd6e0a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ dependencies {
    compile 'de.cketti.safecontentresolver:safe-content-resolver-v14:0.9.0'
    compile 'com.github.amlcurran.showcaseview:library:5.4.1'
    compile 'com.squareup.moshi:moshi:1.2.0'
    compile 'com.jakewharton.timber:timber:4.5.1'

    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

+3 −4
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.util.Log;
import timber.log.Timber;

import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.helper.Utility;
@@ -760,7 +760,7 @@ public class Account implements BaseAccount, StoreConfig {
        try {
            getLocalStore().resetVisibleLimits(getDisplayCount());
        } catch (MessagingException e) {
            Log.e(K9.LOG_TAG, "Unable to reset visible limits", e);
            Timber.e(e, "Unable to reset visible limits");
        }

    }
@@ -953,8 +953,7 @@ public class Account implements BaseAccount, StoreConfig {
                switchLocalStorage(id);
                successful = true;
            } catch (MessagingException e) {
                Log.e(K9.LOG_TAG, "Switching local storage provider from " +
                      mLocalStorageProviderId + " to " + id + " failed.", e);
                Timber.e(e, "Switching local storage provider from %s to %s failed.", mLocalStorageProviderId, id);
            }

            // if migration to/from SD-card failed once, it will fail again.
+37 −22
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.StrictMode;
import android.text.format.Time;
import android.util.Log;

import com.fsck.k9.Account.SortType;
import com.fsck.k9.activity.MessageCompose;
@@ -45,6 +44,9 @@ import com.fsck.k9.service.MailService;
import com.fsck.k9.service.ShutdownReceiver;
import com.fsck.k9.service.StorageGoneReceiver;
import com.fsck.k9.widget.list.MessageListWidgetProvider;
import timber.log.Timber;
import timber.log.Timber.DebugTree;


public class K9 extends Application {
    /**
@@ -135,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
@@ -416,7 +418,7 @@ public class K9 extends Application {
                try {
                    queue.put(new Handler());
                } catch (InterruptedException e) {
                    Log.e(K9.LOG_TAG, "", e);
                    Timber.e(e);
                }
                Looper.loop();
            }
@@ -426,13 +428,13 @@ public class K9 extends Application {
        try {
            final Handler storageGoneHandler = queue.take();
            registerReceiver(receiver, filter, null, storageGoneHandler);
            Log.i(K9.LOG_TAG, "Registered: unmount receiver");
            Timber.i("Registered: unmount receiver");
        } catch (InterruptedException e) {
            Log.e(K9.LOG_TAG, "Unable to register unmount receiver", e);
            Timber.e(e, "Unable to register unmount receiver");
        }

        registerReceiver(new ShutdownReceiver(), new IntentFilter(Intent.ACTION_SHUTDOWN));
        Log.i(K9.LOG_TAG, "Registered: shutdown receiver");
        Timber.i("Registered: shutdown receiver");
    }

    public static void save(StorageEditor editor) {
@@ -565,21 +567,19 @@ public class K9 extends Application {
                intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
                intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM_SELF, account.isAnIdentity(message.getFrom()));
                K9.this.sendBroadcast(intent);
                if (K9.DEBUG)
                    Log.d(K9.LOG_TAG, "Broadcasted: action=" + action
                          + " account=" + account.getDescription()
                          + " folder=" + folder
                          + " message uid=" + message.getUid()
                         );

                Timber.d("Broadcasted: action=%s account=%s folder=%s message uid=%s",
                        action,
                        account.getDescription(),
                        folder,
                        message.getUid());
            }

            private void updateUnreadWidget() {
                try {
                    UnreadWidgetProvider.updateUnreadCount(K9.this);
                } catch (Exception e) {
                    if (K9.DEBUG) {
                        Log.e(LOG_TAG, "Error while updating unread widget(s)", e);
                    }
                    Timber.e(e, "Error while updating unread widget(s)");
                }
            }

@@ -589,8 +589,8 @@ public class K9 extends Application {
                } catch (RuntimeException e) {
                    if (BuildConfig.DEBUG) {
                        throw e;
                    } else if (K9.DEBUG) {
                        Log.e(LOG_TAG, "Error while updating message list widget", e);
                    } else {
                        Timber.e(e, "Error while updating message list widget");
                    }
                }
            }
@@ -671,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);
@@ -799,13 +799,12 @@ public class K9 extends Application {
    protected void notifyObservers() {
        synchronized (observers) {
            for (final ApplicationAware aware : observers) {
                if (K9.DEBUG) {
                    Log.v(K9.LOG_TAG, "Initializing observer: " + aware);
                }
                Timber.v("Initializing observer: %s", aware);

                try {
                    aware.initializeComponent(this);
                } catch (Exception e) {
                    Log.w(K9.LOG_TAG, "Failure when notifying " + aware, e);
                    Timber.w(e, "Failure when notifying %s", aware);
                }
            }

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

}
+6 −5
Original line number Diff line number Diff line
@@ -10,13 +10,14 @@ import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.Log;
import timber.log.Timber;

import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.preferences.StorageEditor;
import com.fsck.k9.preferences.Storage;


public class Preferences {

    private static Preferences preferences;
@@ -40,7 +41,7 @@ public class Preferences {
        mStorage = Storage.getStorage(context);
        mContext = context;
        if (mStorage.isEmpty()) {
            Log.i(K9.LOG_TAG, "Preferences storage is zero-size, importing from Android-style preferences");
            Timber.i("Preferences storage is zero-size, importing from Android-style preferences");
            StorageEditor editor = mStorage.edit();
            editor.copy(context.getSharedPreferences("AndroidMail.Main", Context.MODE_PRIVATE));
            editor.commit();
@@ -128,7 +129,7 @@ public class Preferences {
        try {
            RemoteStore.removeInstance(account);
        } catch (Exception e) {
            Log.e(K9.LOG_TAG, "Failed to reset remote store for account " + account.getUuid(), e);
            Timber.e(e, "Failed to reset remote store for account %s", account.getUuid());
        }
        LocalStore.removeAccount(account);

@@ -176,8 +177,8 @@ public class Preferences {
            try {
                return Enum.valueOf(defaultEnum.getDeclaringClass(), stringPref);
            } catch (IllegalArgumentException ex) {
                Log.w(K9.LOG_TAG, "Unable to convert preference key [" + key +
                        "] value [" + stringPref + "] to enum of type " + defaultEnum.getDeclaringClass(), ex);
                Timber.w(ex, "Unable to convert preference key [%s] value [%s] to enum of type %s",
                        key, stringPref, defaultEnum.getDeclaringClass());

                return defaultEnum;
            }
+6 −3
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package com.fsck.k9;

import android.os.Handler;
import android.util.Log;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Handler;

import timber.log.Timber;


/**
 * This class used to "throttle" a flow of events.
 *
@@ -94,7 +97,7 @@ public class Throttle {
    }

    private void debugLog(String message) {
        Log.d(K9.LOG_TAG, "Throttle: [" + mName + "] " + message);
        Timber.d("Throttle: [%s] %s", mName, message);
    }

    private boolean isCallbackScheduled() {
Loading