//获取方法名: public static String getCurrentMethodName() { int level = 1; StackTraceElement[] stacks = new Throwable().getStackTrace(); String methodName = stacks[level].getMethodName(); return methodName; } //获取类名: public static String getCurrentClassName() { int level = 1; StackTraceElement[] stacks = new Throwable().getStackTrace(); String className = stacks[level].getClassName(); return className; }
//获取行号: public static int getLineNumber() { int level = 1; StackTraceElement[] stacks = new Throwable().getStackTrace(); int lineNumber = stacks[level].getLineNumber(); return lineNumber; }