Back to project page android-utils.
The source code is released under:
Apache License
If you think the Android project android-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.omegar.android.utils; //from w ww . j av a2 s. co m import android.annotation.SuppressLint; import android.util.Log; import com.crashlytics.android.Crashlytics; /** * Writes log messages to logcat with or without location link (eclipse format). * Logs exceptions and breadcrumbs in Crashlytics. */ @SuppressWarnings("unused") public class Logger { private static final int MIN_WITH_SOURCE_LINK_PRIORITY = Log.INFO; private static final int MIN_CRASHLYTICS_LOG_PRIORITY = Log.VERBOSE; public static void v(String message) { log(Log.VERBOSE, message); } public static void i(String message) { log(Log.INFO, message); } public static void d(String message) { log(Log.DEBUG, message); } public static void w(String message) { log(Log.WARN, message); } public static void w(String message, Throwable exception) { log(Log.WARN, message + '\n' + Log.getStackTraceString(exception)); } public static void e(String message) { log(Log.ERROR, message); } private static void log(int priority, String msg) { String message = createMessage(msg, priority); if (BuildConfig.DEBUG) { Log.println(priority, createTag(), message); } if (!BuildConfig.DEBUG && priority >= MIN_CRASHLYTICS_LOG_PRIORITY) { Crashlytics.log(message); } } public static void e(String message, Throwable exception) { log(Log.ERROR, message + '\n' + Log.getStackTraceString(exception)); if (!BuildConfig.DEBUG) { Crashlytics.logException(exception); } } @SuppressLint("DefaultLocale") private static String createMessage(String message, int priority) { StackTraceElement stackTraceElement = getLoggedStackTraceElement(); String methodName = stackTraceElement.getMethodName(); int lineNumber = stackTraceElement.getLineNumber(); if (BuildConfig.DEBUG && priority >= MIN_WITH_SOURCE_LINK_PRIORITY) { return String.format("%s\nat %s.%s(%s:%d)", message, stackTraceElement.getClassName(), methodName, stackTraceElement.getFileName(), lineNumber); } else { return String.format("%s (%s:%d)", message, methodName, lineNumber); } } private static String createTag() { return getLoggedStackTraceElement().getFileName().replace(".java", ""); } private static StackTraceElement getLoggedStackTraceElement() { return Thread.currentThread().getStackTrace()[6]; } }