Android获取Java类名/文件名/方法名/行号

时间:2022-05-27 10:30:35
//ep.getStackTrace()[0].getClassName():0为当前方法类名;1为调用者类名.
Exception ep = new Exception();                                                                                              
Log.d(TAG,”xxx———> Class: " + ep.getStackTrace()[0].getClassName() + " Filename: " +ep.getStackTrace()[0].getFileName()  + " func: " + ep.getStackTrace()[0].getMethodName() + " line: " + ep.getStackTrace()[0].getLineNumber());