If you think the Android project encrypted-camera listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.andrewreitz.encryptedcamera.logging;
/*fromwww.java2s.com*/import com.crashlytics.android.Crashlytics;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import timber.log.Timber;
publicfinalclass CrashlyticsTree extends Timber.HollowTree {
privatestaticfinal Pattern ANONYMOUS_CLASS = Pattern.compile("\\$\\d+$");
privateenum LogLevel {
INFO,
ERROR,
WARNING
}
@Override publicvoid i(String message, Object... args) {
log(LogLevel.INFO, createTag(), formatString(message, args));
}
@Override publicvoid i(Throwable t, String message, Object... args) {
log(LogLevel.INFO, createTag(), formatString(message, args), t);
}
@Override publicvoid w(String message, Object... args) {
log(LogLevel.WARNING, createTag(), formatString(message, args));
}
@Override publicvoid w(Throwable t, String message, Object... args) {
log(LogLevel.WARNING, createTag(), formatString(message, args), t);
}
@Override publicvoid e(String message, Object... args) {
log(LogLevel.ERROR, createTag(), formatString(message, args));
}
@Override publicvoid e(Throwable t, String message, Object... args) {
log(LogLevel.ERROR, createTag(), formatString(message, args), t);
}
privatevoid log(LogLevel logLevel, String tag, String message) {
log(logLevel, tag, message, null);
}
privatevoid log(LogLevel logLevel, String tag, String message, Throwable t) {
Crashlytics.log(String.format("%s/%s: %s", logLevel, tag, message));
Crashlytics.logException(t); // always log even if null, crashylitcs ignores them
}
/**
* Create a tag from the calling class (4 up).
* This is not exactly fast but then again this really shouldn't be called a lot
*/privatestatic String createTag() {
String tag = new Throwable().getStackTrace()[4].getClassName();
Matcher m = ANONYMOUS_CLASS.matcher(tag);
if (m.find()) {
tag = m.replaceAll("");
}
return tag.substring(tag.lastIndexOf('.') + 1);
}
privatestatic String formatString(String message, Object... args) {
return args.length == 0 ? message : String.format(message, args);
}
}