关闭

Android初学之------双击log跳转到log输出位置

标签: logcat
944人阅读 评论(0) 收藏 举报
分类:
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 + ")");

    }




public static String lineOut() {
	    int level = 3;
	    StackTraceElement[] traces;
	    traces = Thread.currentThread().getStackTrace();
	    return (" at "  + traces[level] + " " );
	}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:91388次
    • 积分:1722
    • 等级:
    • 排名:千里之外
    • 原创:87篇
    • 转载:4篇
    • 译文:1篇
    • 评论:19条
    最新评论