Skip to content

Commit

Permalink
Timber library p1
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwhiuk authored and Valodim committed Mar 22, 2017
1 parent cf02795 commit 878fdc0
Show file tree
Hide file tree
Showing 35 changed files with 207 additions and 278 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
androidCompileSdkVersion=25
androidBuildToolsVersion=25.0.2
androidSupportLibraryVersion=25.2.0
timberVersion=4.5.1

robolectricVersion=3.2.2
junitVersion=4.12
Expand Down
1 change: 1 addition & 0 deletions k9mail-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
compile 'com.jcraft:jzlib:1.0.7'
compile 'com.beetstra.jutf7:jutf7:1.0.0'
compile "com.android.support:support-annotations:${androidSupportLibraryVersion}"
compile "com.jakewharton.timber:timber:${timberVersion}"

androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.madgag.spongycastle:pg:1.51.0.0'
Expand Down
9 changes: 3 additions & 6 deletions k9mail-library/src/main/java/com/fsck/k9/mail/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import org.apache.james.mime4j.dom.address.Mailbox;
import org.apache.james.mime4j.dom.address.MailboxList;
import org.apache.james.mime4j.field.address.AddressBuilder;
import timber.log.Timber;

import android.text.TextUtils;
import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;
import android.util.Log;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;

public class Address implements Serializable {
private static final Pattern ATOM = Pattern.compile("^(?:[a-zA-Z0-9!#$%&'*+\\-/=?^_`{|}~]|\\s)+$");
Expand Down Expand Up @@ -152,12 +150,11 @@ public static Address[] parse(String addressList) {
Mailbox mailbox = (Mailbox) address;
addresses.add(new Address(mailbox.getLocalPart() + "@" + mailbox.getDomain(), mailbox.getName(), false));
} else {
Log.e(LOG_TAG, "Unknown address type from Mime4J: "
+ address.getClass().toString());
Timber.e("Unknown address type from Mime4J: %s", address.getClass().toString());
}
}
} catch (MimeException pe) {
Log.e(LOG_TAG, "MimeException in Address.parse()", pe);
Timber.e(pe, "MimeException in Address.parse()");
//but we do an silent failover : we just use the given string as name with empty address
addresses.add(new Address(null, addressList, false));
}
Expand Down
6 changes: 2 additions & 4 deletions k9mail-library/src/main/java/com/fsck/k9/mail/Folder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import java.util.Map;
import java.util.Set;

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

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;

public abstract class Folder<T extends Message> {
private String status = null;
Expand Down Expand Up @@ -133,8 +132,7 @@ public void fetchPart(Message message, Part part,
// This is causing trouble. Disabled for now. See issue 1733
//throw new RuntimeException("fetchPart() not implemented.");

if (K9MailLib.isDebug())
Log.d(LOG_TAG, "fetchPart() not implemented.");
Timber.d("fetchPart() not implemented.");
}

public abstract void delete(boolean recurse) throws MessagingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class K9MailLib {
private K9MailLib() {
}

public static final String LOG_TAG = "k9";
public static final int PUSH_WAKE_LOCK_TIMEOUT = 60000;
public static final String IDENTITY_HEADER = "X-K9mail-Identity";

Expand Down
2 changes: 0 additions & 2 deletions k9mail-library/src/main/java/com/fsck/k9/mail/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import com.fsck.k9.mail.filter.CountingOutputStream;
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;

public abstract class Message implements Part, Body {

public enum RecipientType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.codec.QuotedPrintableOutputStream;
import org.apache.james.mime4j.util.MimeUtil;
import timber.log.Timber;


/**
Expand Down Expand Up @@ -136,7 +137,7 @@ public void close() throws IOException {
try {
super.close();
} finally {
Log.d(K9MailLib.LOG_TAG, "deleting temp file");
Timber.d("Deleting temporary binary file");
mFile.delete();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.fsck.k9.mail.internet;

import android.util.Log;

import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part;

import org.apache.commons.io.IOUtils;
import timber.log.Timber;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.util.Locale;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
import static com.fsck.k9.mail.internet.JisSupport.SHIFT_JIS;

public class CharsetSupport {
Expand Down Expand Up @@ -111,8 +109,7 @@ static String readToString(InputStream in, String charset) throws IOException {
}

if (charset.matches(rule[0])) {
Log.e(LOG_TAG, "I don't know how to deal with the charset " + charset +
". Falling back to " + rule[1]);
Timber.e("I don't know how to deal with the charset %s. Falling back to %s", charset, rule[1]);
charset = rule[1];
try {
supported = Charset.isSupported(charset);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package com.fsck.k9.mail.internet;

import android.util.Log;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import java.io.ByteArrayInputStream;
Expand All @@ -11,8 +10,7 @@
import org.apache.james.mime4j.codec.Base64InputStream;
import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
import org.apache.james.mime4j.util.CharsetUtil;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
import timber.log.Timber;


/**
Expand Down Expand Up @@ -169,7 +167,7 @@ private static String decodeEncodedWord(String body, int begin, int end, Message
}

if (encodedText.isEmpty()) {
Log.w(LOG_TAG, "Missing encoded text in encoded word: '" + body.substring(begin, end) + "'");
Timber.w("Missing encoded text in encoded word: '%s'", body.substring(begin, end));
return null;
}

Expand All @@ -178,7 +176,7 @@ private static String decodeEncodedWord(String body, int begin, int end, Message
} else if (encoding.equalsIgnoreCase("B")) {
return DecoderUtil.decodeB(encodedText, charset);
} else {
Log.w(LOG_TAG, "Warning: Unknown encoding in encoded word '" + body.substring(begin, end) + "'");
Timber.w("Warning: Unknown encoding in encoded word '%s'", body.substring(begin, end));
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.internet.Viewable.Flowed;
import org.apache.commons.io.input.BoundedInputStream;
import timber.log.Timber;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
import static com.fsck.k9.mail.internet.CharsetSupport.fixupCharset;
import static com.fsck.k9.mail.internet.MimeUtility.getHeaderParameter;
import static com.fsck.k9.mail.internet.MimeUtility.isFormatFlowed;
Expand Down Expand Up @@ -62,9 +62,9 @@ public static String getTextFromPart(Part part, long textSizeLimit) {
throw new MessagingException("Provided invalid part");
}
} catch (IOException e) {
Log.e(LOG_TAG, "Unable to getTextFromPart", e);
Timber.e(e, "Unable to getTextFromPart");
} catch (MessagingException e) {
Log.e(LOG_TAG, "Unable to getTextFromPart", e);
Timber.e("Unable to getTextFromPart");
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
import org.apache.james.mime4j.util.MimeUtil;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;


public class MimeUtility {
public static final String DEFAULT_ATTACHMENT_MIME_TYPE = "application/octet-stream";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.fsck.k9.mail.filter.SignSafeOutputStream;
import org.apache.james.mime4j.codec.QuotedPrintableOutputStream;
import org.apache.james.mime4j.util.MimeUtil;
import timber.log.Timber;


public class TextBody implements Body, SizeAware {
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
Expand Down Expand Up @@ -67,7 +69,7 @@ public InputStream getInputStream() throws MessagingException {
}
return new ByteArrayInputStream(b);
} catch (UnsupportedEncodingException uee) {
Log.e(K9MailLib.LOG_TAG, "Unsupported charset: " + charset, uee);
Timber.e(uee, "Unsupported charset: " + charset);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import com.fsck.k9.mail.filter.Base64;
import org.json.JSONException;
import org.json.JSONObject;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
import timber.log.Timber;


/**
Expand All @@ -23,7 +22,7 @@ public static boolean shouldRetry(String response, String host) {
String decodedResponse = Base64.decode(response);

if (K9MailLib.isDebug()) {
Log.v(LOG_TAG, "Challenge response: " + decodedResponse);
Timber.v("Challenge response: " + decodedResponse);
}

try {
Expand All @@ -33,7 +32,7 @@ public static boolean shouldRetry(String response, String host) {
return false;
}
} catch (JSONException jsonException) {
Log.e(LOG_TAG, "Error decoding JSON response from: " + host + ". Response was: " + decodedResponse);
Timber.e("Error decoding JSON response from: " + host + ". Response was: " + decodedResponse);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fsck.k9.mail.power;


import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -8,11 +9,9 @@
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.util.Log;

import com.fsck.k9.mail.K9MailLib;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
import timber.log.Timber;


public class TracingPowerManager {
Expand All @@ -26,7 +25,7 @@ public static synchronized TracingPowerManager getPowerManager(Context context)
Context appContext = context.getApplicationContext();
if (tracingPowerManager == null) {
if (K9MailLib.isDebug()) {
Log.v(LOG_TAG, "Creating TracingPowerManager");
Timber.v("Creating TracingPowerManager");
}
tracingPowerManager = new TracingPowerManager(appContext);
}
Expand Down Expand Up @@ -56,15 +55,15 @@ public TracingWakeLock(int flags, String ntag) {
wakeLock = pm.newWakeLock(flags, tag);
id = wakeLockId.getAndIncrement();
if (K9MailLib.isDebug()) {
Log.v(LOG_TAG, "TracingWakeLock for tag " + tag + " / id " + id + ": Create");
Timber.v("TracingWakeLock for tag " + tag + " / id " + id + ": Create");
}
}
public void acquire(long timeout) {
synchronized (wakeLock) {
wakeLock.acquire(timeout);
}
if (K9MailLib.isDebug()) {
Log.v(LOG_TAG, "TracingWakeLock for tag " + tag + " / id " + id + " for " + timeout + " ms: acquired");
Timber.v("TracingWakeLock for tag " + tag + " / id " + id + " for " + timeout + " ms: acquired");
}
raiseNotification();
if (startTime == null) {
Expand All @@ -78,7 +77,7 @@ public void acquire() {
}
raiseNotification();
if (K9MailLib.isDebug()) {
Log.w(LOG_TAG, "TracingWakeLock for tag " + tag + " / id " + id + ": acquired with no timeout. K-9 Mail should not do this");
Timber.w("TracingWakeLock for tag " + tag + " / id " + id + ": acquired with no timeout. K-9 Mail should not do this");
}
if (startTime == null) {
startTime = SystemClock.elapsedRealtime();
Expand All @@ -94,11 +93,11 @@ public void release() {
if (startTime != null) {
Long endTime = SystemClock.elapsedRealtime();
if (K9MailLib.isDebug()) {
Log.v(LOG_TAG, "TracingWakeLock for tag " + tag + " / id " + id + ": releasing after " + (endTime - startTime) + " ms, timeout = " + timeout + " ms");
Timber.v("TracingWakeLock for tag " + tag + " / id " + id + ": releasing after " + (endTime - startTime) + " ms, timeout = " + timeout + " ms");
}
} else {
if (K9MailLib.isDebug()) {
Log.v(LOG_TAG, "TracingWakeLock for tag " + tag + " / id " + id + ", timeout = " + timeout + " ms: releasing");
Timber.v("TracingWakeLock for tag " + tag + " / id " + id + ", timeout = " + timeout + " ms: releasing");
}
}
cancelNotification();
Expand Down Expand Up @@ -128,11 +127,11 @@ private void raiseNotification() {
public void run() {
if (startTime != null) {
Long endTime = SystemClock.elapsedRealtime();
Log.i(LOG_TAG, "TracingWakeLock for tag " + tag + " / id " + id + ": has been active for "
Timber.i("TracingWakeLock for tag " + tag + " / id " + id + ": has been active for "
+ (endTime - startTime) + " ms, timeout = " + timeout + " ms");

} else {
Log.i(LOG_TAG, "TracingWakeLock for tag " + tag + " / id " + id + ": still active, timeout = " + timeout + " ms");
Timber.i("TracingWakeLock for tag " + tag + " / id " + id + ": still active, timeout = " + timeout + " ms");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
import android.net.SSLCertificateSocketFactory;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;

import com.fsck.k9.mail.MessagingException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
import timber.log.Timber;


/**
Expand Down Expand Up @@ -113,8 +111,7 @@ public class DefaultTrustedSocketFactory implements TrustedSocketFactory {
*/
supportedProtocols = sock.getSupportedProtocols();
} catch (Exception e) {
Log.e(LOG_TAG, "Error getting information about available SSL/TLS ciphers and " +
"protocols", e);
Timber.e(e, "Error getting information about available SSL/TLS ciphers and protocols");
}

if (hasWeakSslImplementation()) {
Expand Down Expand Up @@ -232,7 +229,7 @@ private static void setHostnameViaReflection(SSLSocket socket, String hostname)
try {
socket.getClass().getMethod("setHostname", String.class).invoke(socket, hostname);
} catch (Throwable e) {
Log.e(LOG_TAG, "Could not call SSLSocket#setHostname(String) method ", e);
Timber.e(e, "Could not call SSLSocket#setHostname(String) method ");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import android.os.Build;
import android.security.KeyChain;
import android.security.KeyChainException;
import android.util.Log;

import com.fsck.k9.mail.CertificateValidationException;
import com.fsck.k9.mail.MessagingException;
import timber.log.Timber;

import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
import static com.fsck.k9.mail.CertificateValidationException.Reason;
import static com.fsck.k9.mail.CertificateValidationException.Reason.RetrievalFailure;

Expand Down Expand Up @@ -204,10 +203,10 @@ private String chooseAlias(String[] keyTypes, Principal[] issuers) {
return mAlias;
}
}
Log.w(LOG_TAG, "Client certificate " + mAlias + " not issued by any of the requested issuers");
Timber.w("Client certificate " + mAlias + " not issued by any of the requested issuers");
return null;
}
Log.w(LOG_TAG, "Client certificate " + mAlias + " does not match any of the requested key types");
Timber.w("Client certificate " + mAlias + " does not match any of the requested key types");
return null;
}
}
Loading

0 comments on commit 878fdc0

Please sign in to comment.