Created
May 20, 2015 18:02
-
-
Save patrickbaumann/6a77f08a47abe76960da to your computer and use it in GitHub Desktop.
Example of how to wrap android.util.Log so that the tag is managed based on class name or logger name.
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
/** | |
* Example of how to wrap android.util.Log so that the tag is managed based on class name or logger name. | |
*/ | |
public class MyLogger { | |
private final String mTag; | |
public MyLogger(String name) { | |
mTag = "Application:" + name; | |
} | |
public MyLogger(Class clazz) { | |
this(clazz.getSimpleName()); | |
} | |
public void v(String msg) { | |
Log.v(mTag, msg); | |
} | |
public void v(String msg, Throwable th) { | |
Log.v(mTag, msg, th); | |
} | |
public void d(String msg) { | |
Log.d(mTag, msg); | |
} | |
public void d(String msg, Throwable th) { | |
Log.d(mTag, msg, th); | |
} | |
public void i(String msg) { | |
Log.i(mTag, msg); | |
} | |
public static void i(String msg, Throwable th) { | |
Log.i(mTag, msg, th); | |
} | |
public static void w(String msg) { | |
Log.w(mTag, msg); | |
} | |
public static void w(String msg, Throwable th) { | |
Log.w(mTag, msg, th); | |
} | |
public static void e(String msg) { | |
Log.e(mTag, msg); | |
} | |
public static void e(String msg, Throwable th) { | |
Log.e(mTag, msg, th); | |
} | |
public static void wtf(String msg) { | |
Log.wtf(mTag, msg); | |
} | |
public static void wtf(String msg, Throwable th) { | |
Log.wtf(mTag, msg, th); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment