Created
August 13, 2013 22:07
-
-
Save Bencodes/6226187 to your computer and use it in GitHub Desktop.
andorid.util.Log wrapper that automatically grabs tags from the stack trace and adds string formatting in.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Log { | |
public static void d (final String format, final Object... params) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.d(getTagFromStackTrace(), String.format(format, params)); | |
} | |
} | |
public static void d (final Throwable e) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.d(getTagFromStackTrace(), "", e); | |
} | |
} | |
public static void e (final String format, final Object... params) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.e(getTagFromStackTrace(), String.format(format, params)); | |
} | |
} | |
public static void e (final Throwable e) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.e(getTagFromStackTrace(), "", e); | |
} | |
} | |
public static void i (final String format, final Object... params) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.i(getTagFromStackTrace(), String.format(format, params)); | |
} | |
} | |
public static void i (final Throwable e) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.i(getTagFromStackTrace(), "", e); | |
} | |
} | |
public static void w (final Throwable e) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.w(getTagFromStackTrace(), e); | |
} | |
} | |
public static void w (final String format, final Object... params) { | |
if (BuildConfig.DEBUG) { | |
android.util.Log.w(getTagFromStackTrace(), String.format(format, params)); | |
} | |
} | |
private static final String getTagFromStackTrace () { | |
// Find the calling class | |
return Thread.currentThread().getStackTrace()[4].getFileName().replace(".java", ""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment