Skip to content

Instantly share code, notes, and snippets.

@francodriansetti
Created April 12, 2016 12:28
Show Gist options
  • Save francodriansetti/aace2002dedc40ad5d53b43c726b5556 to your computer and use it in GitHub Desktop.
Save francodriansetti/aace2002dedc40ad5d53b43c726b5556 to your computer and use it in GitHub Desktop.
import android.util.Log;
/**
* LL -- extended logging abilities
*
* LL exists to allow builders to leave logging calls in production code; it
* provides overrides for android.util.Log's .d, .i, .v and .w methods that will
* be suppressed when logLevel is set to 0.
*
* @author Franco Driansetti David Lomuscio
*
*/
public class LL {
// Define a log-level
public static int logLevel = 0;
public static final int LL_ERROR = 1;
public static final int LL_WARNING = 2;
public static final int LL_INFO = 3;
public static final int LL_DEBUG = 4;
public static final int LL_VERBOSE = 5;
public static final int LL_VERBOSEFUNC = 6;
public static void setLogLevel(int level) {
logLevel = level;
}
// Override Log.e()
public static void e(String tag, String msg) {
if (LL_ERROR >= logLevel) Log.d(tag, "ERROR " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg);
}
public static void e(String tag, String msg, Throwable tr) {
if (LL_ERROR >= logLevel) Log.d(tag, "ERROR " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg, tr);
}
// Override Log.w()
public static void w(String tag, String msg) {
if (LL_WARNING >= logLevel) Log.d(tag, "WARNING " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg);
}
public static void w(String tag, String msg, Throwable tr) {
if (LL_WARNING >= logLevel) Log.d(tag, "WARNING " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg, tr);
}
// Override Log.i()
public static void i(String tag, String msg) {
if (LL_INFO >= logLevel) Log.d(tag, "INFO " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg);
}
public static void i(String tag, String msg, Throwable tr) {
if (LL_INFO >= logLevel) Log.d(tag, "INFO " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg, tr);
}
// Override Log.d()
public static void d(String tag, String msg) {
if (LL_DEBUG >= logLevel) Log.d(tag, "DEBUG " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg);
}
public static void d(String tag, String msg, Throwable tr) {
if (LL_DEBUG >= logLevel) Log.d(tag, "DEBUG " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg, tr);
}
// Override Log.v()
public static void v(String tag, String msg) {
if (LL_VERBOSE >= logLevel) Log.d(tag, "VERBOSE " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg);
}
public static void v(String tag, String msg, Throwable tr) {
if (LL_VERBOSE >= logLevel) Log.d(tag, "VERBOSE " + Thread.currentThread().getStackTrace()[1].getMethodName() + " " + msg, tr);
}
public static void LOGFSTART (String tag) {
if (LL_VERBOSEFUNC >= logLevel) Log.d(tag, "START " + Thread.currentThread().getStackTrace()[1].getMethodName());
}
public static void LOGFEND (String tag) {
if (LL_VERBOSEFUNC >= logLevel) Log.d(tag, "END " + Thread.currentThread().getStackTrace()[1].getMethodName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment