Skip to content

Instantly share code, notes, and snippets.

@susemi99

susemi99/Logg.java

Last active Mar 29, 2018
Embed
What would you like to do?
Clickable in Logcat
public class Logg {
public static void v(String msg) {
Log.v(tag(), msg);
}
public static void d(String msg) {
Log.d(tag(), msg);
}
public static void i(String msg) {
Log.i(tag(), msg);
}
public static void w(String msg) {
Log.w(tag(), msg);
}
public static void e(String msg) {
Log.e(tag(), msg);
}
public static void e(Exception e) {
e.printStackTrace();
}
public static void e(Throwable e) {
e.printStackTrace();
}
private static String tag() {
int level = 4;
StackTraceElement trace = Thread.currentThread().getStackTrace()[level];
String fileName = trace.getFileName();
String classPath = trace.getClassName();
String className = classPath.substring(classPath.lastIndexOf(".") + 1);
String methodName = trace.getMethodName();
int lineNumber = trace.getLineNumber();
return "APP# " + className + "." + methodName + "(" + fileName + ":" + lineNumber + ")";
}
}
Logg.v("qwertyuiop");
Logg.d("qwertyuiop");
Logg.i("qwertyuiop");
Logg.w("qwertyuiop");
Logg.e("qwertyuiop");
// V/APP# MainActivity.onCreate(MainActivity.java:13): qwertyuiop
// D/APP# MainActivity.onCreate(MainActivity.java:14): qwertyuiop
// I/APP# MainActivity.onCreate(MainActivity.java:15): qwertyuiop
// W/APP# MainActivity.onCreate(MainActivity.java:16): qwertyuiop
// E/APP# MainActivity.onCreate(MainActivity.java:17): qwertyuiop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.