android debug, print class name, line number
来源:互联网 发布:淘宝客服问题大全 编辑:程序博客网 时间:2024/05/19 00:16
在Android调试的时候,有时候需要打印指定的行号和类名。
下面是一个调试log的类。
package com.project.mocha_doctor.common;import android.util.Log;public class SmabDebug {private final static boolean DEBUG = true;private final static String TAG = "YXH";private final static int pos = 3;public static void log(String message) { if (DEBUG) { String fullClassName = Thread.currentThread().getStackTrace()[pos].getClassName(); String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1); String methodName = Thread.currentThread().getStackTrace()[pos].getMethodName(); int lineNumber = Thread.currentThread().getStackTrace()[pos].getLineNumber(); Log.i(TAG + " - " + className + "." + methodName + "():" + lineNumber, message); } }/*0VMStack.getThreadStackTrace()1Thread.getStackTrace()2SmabDebug.printStack()3HttpRequestTask.onPostExecute()4HttpRequestTask.onPostExecute()5AsyncTask.finish()6AsyncTask.access$600()7AsyncTask$InternalHandler.handleMessage()8Handler.dispatchMessage()9Looper.loop()10ActivityThread.main()11Method.invokeNative()12Method.invoke()13ZygoteInit$MethodAndArgsCaller.run()14ZygoteInit.main()15NativeStart.main() If the value = 3, it means the caller Class. */public static void printStack (){int deep = Thread.currentThread().getStackTrace().length;for (int i = 0; i < deep; i ++){ String fullClassName = Thread.currentThread().getStackTrace()[i].getClassName(); String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1); String methodName = Thread.currentThread().getStackTrace()[i].getMethodName(); Log.i(TAG, className + "." + methodName + "()");}}}调用的时候只需要简单的
SmabDebug.log ( "Status code ---->" + codeStr);
log输出为如下, 不会输出这个类名。
I/YXH - ServerTimeSyncUp$GETRequestListener.ServerResponse():86(13348):Status code----->145
0 0
- android debug, print class name, line number
- debug absent line number information
- Eclipse Debug Absent Line Number Information
- Debug Print
- Debug Print
- Eclipse debug时报错“Absent Line Number Information”
- eclipse debug JDK中源代码时出现 missing line number
- eclipse无法打断点,提示debug absent line number information
- debug log print function
- unable to install breakpoint in ...(file name) due to miss line number attributes.
- Print the macro number
- SysLog and Print class
- Use Class print
- [Debug]Android 编辑xml中Incorrect line ending错误解决方法
- debug模式进行调试时出现:reason:absent line number informat错误
- 无法debug断点跟踪JDK源代码——missing line number attributes的解决方法
- debug时报Unable to install breakpoint in XX due to missing line number attributes
- 无法debug断点跟踪JDK源代码——missing line number attributes的解决方法
- GeeksforGeeks: Given a sorted dictionary of an alien language, find order of characters
- Leetcode_String To Integer
- 辛星与您解读PHP页面跳转的几种实现方式
- Leetcode_Zig Zag Conversion
- 辛星和您彻底解读PHP中的引用
- android debug, print class name, line number
- Cache Operation in AngularJS
- 百度编辑器换皮肤,价格好商量
- LPCXpresso的下载
- 2014年7月24日 5点57分
- WEB开发中常用的子页面调用父页面方式
- C# Lua5.2.3 SandBox 结合
- linux上swap的查看与调整实例大全
- 正确设置Linux swap分区方法详解