獲取類名:
1、在類的實(shí)例中可使用this.getClass().getName();但在static method中不能使用該方法;
2、在static method中使用方法:Thread.currentThread().getStackTrace()[1].getClassName();
獲取方法名:Thread.currentThread().getStackTrace()[1].getMethodName();
獲取代碼行號:Thread.currentThread().getStackTrace()[1].getLineNumber();
Log 代碼:
System.out.println("Class: "+this.getClass().getName()+" method: "+
Thread.currentThread().getStackTrace()[1].getMethodName() +" line:"+
Thread.currentThread().getStackTrace()[1].getLineNumber());