1.
public static String getMethodName() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[stacktrace.length-1];
return e.getMethodName();
}
public static int getLineNo() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[stacktrace.length-1];
return e.getLineNumber();
}
public static String getFileName() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[stacktrace.length-1];
return e.getFileName();
}
2.
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT __FILE__"[" TOSTRING(__LINE__) "]:"__FUNCTION__
宏AT就可以将调用时的文件名和文件行号和方法名打印出来。
打印函数
void WriteDebugInfomation(const char* filelocation, const char *WriteString)
{
printf("%s:%s",filelocation,WriteString);
}
在我们调用的地方就可以直接使用
WriteDebugInfomation(AT,"测试");
3.