Print full call stack on printStackTrace()?

后端 未结 3 1601
Happy的楠姐
Happy的楠姐 2020-11-27 18:57

I need to write small a log analyzer application to process some log files generated by a 3rd party closed source library (having custom logger inside) used in my project. <

3条回答
  •  离开以前
    2020-11-27 19:28

    Can't you do something with Thread.currentThread().getStackTrace()?

    Here's a real simple example which calls a method recursively 20 times and then dumps out the stack of the current thread.

    public class Test {
        public static void main(String[] args) {
            method();
        }
    
        static int x = 0;
        private static void method() {
            if(x>20) {
                StackTraceElement[] elements = Thread.currentThread().getStackTrace();
    
                for(int i=0; i

提交回复
热议问题