From 2531c88f2c8a992aa0c40c9f96e88099dc94139e Mon Sep 17 00:00:00 2001 From: steckbrief Date: Fri, 20 Nov 2015 22:41:30 +0100 Subject: Implements FS#67: Introduce central logging class to use log prefix, new activity to show logcat output and button to copy contents --- .../conversationsplus/utils/Logging.java | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/Logging.java (limited to 'src/main/java/de/thedevstack/conversationsplus/utils/Logging.java') diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java b/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java new file mode 100644 index 00000000..40ec66a0 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java @@ -0,0 +1,124 @@ +package de.thedevstack.conversationsplus.utils; + +import android.util.Log; + +/** + * Created by tzur on 20.11.2015. + */ +public class Logging { + protected static final String LOG_TAG_PREFIX = "thedevstack."; + /** + * Send a {@link Log#VERBOSE} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int v(String tag, String msg) { + return Log.v(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#VERBOSE} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int v(String tag, String msg, Throwable tr) { + return Log.v(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /** + * Send a {@link Log#DEBUG} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int d(String tag, String msg) { + return Log.d(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#DEBUG} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int d(String tag, String msg, Throwable tr) { + return Log.d(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /** + * Send an {@link Log#INFO} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int i(String tag, String msg) { + return Log.i(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#INFO} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int i(String tag, String msg, Throwable tr) { + return Log.i(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /** + * Send a {@link Log#WARN} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int w(String tag, String msg) { + return Log.w(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#WARN} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int w(String tag, String msg, Throwable tr) { + return Log.w(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /* + * Send a {@link #WARN} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param tr An exception to log + */ + public static int w(String tag, Throwable tr) { + return Log.w(Logging.LOG_TAG_PREFIX + tag, Log.getStackTraceString(tr)); + } + + /** + * Send an {@link Log#ERROR} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int e(String tag, String msg) { + return Log.e(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#ERROR} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int e(String tag, String msg, Throwable tr) { + return Log.e(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } +} -- cgit v1.2.3