打印方法路径方法一
/**
* 打印方法路径
*/
public static void printMethodPath() {
//new 一个异常类
Exception exception = new Exception();
//调用者上级类名
Log.i(TAG, "Class0———>:" + exception.getStackTrace()[0].getClassName());
//调用者上级的上级类名
Log.i(TAG, "Class1———>:" + exception.getStackTrace()[1].getClassName());
//调用者上级的方法名
Log.i(TAG, "MethodName0———>:" + exception.getStackTrace()[0].getMethodName());
//调用者上级的上级方法名
Log.i(TAG, "MethodName1———>:" + exception.getStackTrace()[1].getMethodName());
//当前方法行号
Log.i(TAG, "line0———>:" + exception.getStackTrace()[0].getLineNumber());
//调用方法行号
Log.i(TAG, "line1———>:" + exception.getStackTrace()[1].getLineNumber());
}
打印方法路径方法二
/**
* 打印方法路径
* @param type 0:方法开始,1:方法结束,2:方法异常,3:方法
*/
public static void printMethodPath(String type){
Exception exception = new Exception();
try {
if ("0".equals(type)){
type = "方法开始";
}else if("1".equals(type)) {
type = "方法结束";
}else if("2".equals(type)) {
type = "方法异常";
} else {
type = "方法";
}
//exception.getStackTrace()[0].getClassName():0为当前方法类名;1为调用者类名.
Log.i(TAG,"Class———>:" + exception.getStackTrace()[1].getClassName() + exception.getStackTrace()[1].getMethodName() + type + " line:" + exception.getStackTrace()[1].getLineNumber());
} catch (Exception e) {
e.printStackTrace();
FileLog.e(TAG,e.getMessage(),e);
}
}