Is there a way to automatically access Logcat with a double click?

Is there any way to automatically access any Log Logat with a double click?

Actually, when my Android application crashes, I can double-click on the line saying, for example,

at com.myapp.mypackage$Class.function(File.java:117) 

And double-clicking on this line, I am automatically redirected to the corresponding line of my code.

But, when I try to create the same line in another Log, an example:

 Log.e("TAG", "at com.myapp.mypackage$Class.function(File.java:117)"); 

Double-clicking no longer works ...

Any ideas?

+6
source share
2 answers

If you don't mind the mess in your log, you can simply add a new Exception() message to the log message

 Log.e("TAG", "Looky here see", new Exception()); 
+3
source

If you want to create a log-log log log that you can click and go to your line, use the following method to create it:

Enjoy it!

 public static void showLogCat(String tag, String msg) { StackTraceElement[] stackTraceElement = Thread.currentThread() .getStackTrace(); int currentIndex = -1; for (int i = 0; i < stackTraceElement.length; i++) { if (stackTraceElement[i].getMethodName().compareTo("showLogCat") == 0) { currentIndex = i + 1; break; } } String fullClassName = stackTraceElement[currentIndex].getClassName(); String className = fullClassName.substring(fullClassName .lastIndexOf(".") + 1); String methodName = stackTraceElement[currentIndex].getMethodName(); String lineNumber = String .valueOf(stackTraceElement[currentIndex].getLineNumber()); Log.i(tag, msg); Log.i(tag + " position", "at " + fullClassName + "." + methodName + "(" + className + ".java:" + lineNumber + ")"); } 
+8
source

Source: https://habr.com/ru/post/901128/


All Articles