标签:
public class Debug {
public static int line(Exception e) {
StackTraceElement[] trace = e.getStackTrace();
if (trace == null || trace.length == 0)
return -1; //
return trace[0].getLineNumber();
}
public static String fun(Exception e) {
StackTraceElement[] trace = e.getStackTrace();
if (trace == null)
return ""; //
return trace[0].getMethodName();
}
}
使用场景:
public class test {
public static String DI(Exception e) {
return Debug.line(e)+"|"+Debug.fun(e)+"|";
}
public test() {
Log.d(TAG, DI(new Exception())); //这里就输出我们需要的debug信息了
}
}
android开发中怎么通过Log函数输出当前行号和当前函数名
标签:
原文地址:http://www.cnblogs.com/superPerfect/p/4215400.html