Skip to content

Instantly share code, notes, and snippets.

@NunciosChums
Last active March 29, 2018 05:10
Show Gist options
  • Save NunciosChums/3a2ea3dec073012b5493263bd2d42547 to your computer and use it in GitHub Desktop.
Save NunciosChums/3a2ea3dec073012b5493263bd2d42547 to your computer and use it in GitHub Desktop.
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