Skip to content

Instantly share code, notes, and snippets.

@Bencodes
Created December 11, 2012 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bencodes/4256395 to your computer and use it in GitHub Desktop.
Save Bencodes/4256395 to your computer and use it in GitHub Desktop.
A little wrapper around android.util.Log that I usually use.
// Adb with your Logger TAG
adb logcat -s 'MyTag'
// Logging A Message
Logger.i("Tag1", "Something just happend!");
Logger.i("Tag1", "Blah");
Logger.i("Tag2", "Oh");
Logger.i("Tag1", "Hi");
// Example Output
I/MyTag(18070): [Tag1] Something just happened!
I/MyTag(18070): [Tag2] Blah
I/MyTag(18070): [Tag1] Oh
I/MyTag(18070): [Tag1] Hi
public final class Logger {
/**
* This is what shows up in the logcat.
*/
private static final String TAG = "MyTag";
/**
* Prints out a simple message
*
* @param tag Tag that will shown in the logcat.
* @param obj An Object to be printed out.
*/
public static void i (String tag, Object obj) {
Log.i(TAG, format(tag, obj));
}
/**
* Prints out a throwable message
*
* @param tag Tag that will shown in the logcat.
* @param e The Exception that was thrown.
*/
public static void e (String tag, Throwable e) {
Log.e(TAG, tag, e);
}
/**
* Formats the message for the LogCat
*
* @param tag Tag that will shown in the logcat.
* @param obj An Object to be printed.
* @return A formatted String.
*/
private static String format (String tag, Object obj) {
return (String.format("[%s]\t%s", tag, obj.toString()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment