Is there any way to access automatically any Log in Logcat by a double click?

前端 未结 2 2139
粉色の甜心
粉色の甜心 2020-12-11 05:25

Is there any way to access automatically any Log in Logcat by a double click ?

Actually, when there is an error crashing my Android Application, I can double click o

相关标签:
2条回答
  • 2020-12-11 05:37

    If you want to create a log in logcat that can be clicked and go to your line use the following method to create it:

    Enjoy!

    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 + ")");
    
        }
    
    0 讨论(0)
  • 2020-12-11 05:53

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

    Log.e("TAG", "Looky here see", new Exception());
    
    0 讨论(0)
提交回复
热议问题