有没有办法通过双击自动访问 Logcat 中的任何登录?
实际上,当我的 Android 应用程序出现错误时,我可以双击“例如”这一行
at com.myapp.mypackage$Class.function(File.java:117)
双击这一行,我会自动重定向到代码的相关行。
但是,当我尝试在另一个日志中生成同一行时,例如:
Log.e("TAG", "at com.myapp.mypackage$Class.function(File.java:117)");
双击不再起作用......
有什么想法吗?
最佳答案
如果您想在 logcat 中创建一个可以点击并转到您的行的日志,请使用以下方法创建它:
尽情享受吧!
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 + ")");
}
关于android - 有什么方法可以通过双击自动访问 Logcat 中的任何登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8067528/