Created
December 11, 2012 06:45
-
-
Save Bencodes/4256395 to your computer and use it in GitHub Desktop.
A little wrapper around android.util.Log that I usually use.
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
// 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 |
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 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