Code:
package com.example.flink;
import java.util.Date;
public class UserDefinedStackTrace {
public static void main(String[] args) {
getCallLocationName();
}
public static void getCallLocationName() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (int i = stackTrace.length - 1; i >= 0; i--) {
StackTraceElement elem = stackTrace[i];
String theDate = new Date().toString();
String threadName = Thread.currentThread().getName();
System.out.println(String.format("%s : %s : %s(%s:%d)", theDate, threadName, elem.getMethodName(),
elem.getFileName(), elem.getLineNumber()));
}
}
}
Result:
Thu Jul 19 15:24:54 IST 2018 : main : main(UserDefinedStackTrace.java:8) Thu Jul 19 15:24:54 IST 2018 : main : getCallLocationName(UserDefinedStackTrace.java:12) Thu Jul 19 15:24:54 IST 2018 : main : getStackTrace(Thread.java:1552)
No comments:
Post a Comment