如何获得完整的 stackTrace
How to get full stackTrace
我有一个意外错误,它创建了包含很多行和内部不同库的 stackTrace。如果从上到下阅读它,可能会看到除了 2-3 第一个方法之外的每个被调用的方法。看起来像
//Pseudo code
method1_1(){
method2();
}
method1_2(){
method2();
}
method1_3(){
method2();
}
method2(){
method3();
}
method3(){
method4();
}
method4(){
method5();
}
method5(){
method6();
}
StackTrace 只显示了 3-6 个方法,但没有显示第二个,第一个中的哪个调用了第二个?我怎么知道呢?该程序很大,日志每 0,1-0,001 秒写入一次。这就是为什么对每种方法都进行日志记录并不好。我无法对错误建模,它只会发生。我需要知道什么方法会引发该错误。示例中有 6 个 first 方法,但还有更多。
P.S. 跟踪看起来像那样
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.dao.impl.UserDaoServiceImpl.updateUser(UserDaoServiceImpl.java:418)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.dao.impl.UserDaoServiceImpl$$FastClassBySpringCGLIB$32584e.invoke(<generated>)
INFO | 2019/04/11 14:23:20 | at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
INFO | 2019/04/11 14:23:20 | at org.springframework.transaction.interceptor.TransactionInterceptor.proceedWithInvocation(TransactionInterceptor.java:96)
INFO | 2019/04/11 14:23:20 | at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
INFO | 2019/04/11 14:23:20 | at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.dao.impl.UserDaoServiceImpl$$EnhancerBySpringCGLIB$$c376b217.updateUser(<generated>)
INFO | 2019/04/11 14:23:20 | at sun.reflect.GeneratedMethodAccessor936.invoke(Unknown Source)
INFO | 2019/04/11 14:23:20 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
INFO | 2019/04/11 14:23:20 | at java.lang.reflect.Method.invoke(Method.java:498)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
INFO | 2019/04/11 14:23:20 | at com.sun.proxy.$Proxy564.updateUser(Unknown Source)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.mobile.utils.Class2.method3(Class2.java:58)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.mobile.utils.beans.Class3.method2(Class3.java:177)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.mobile.utils.beans.Class3.lambda$method1(Class3.java:117)
INFO | 2019/04/11 14:23:20 | at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
INFO | 2019/04/11 14:23:20 | at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
INFO | 2019/04/11 14:23:20 | at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
INFO | 2019/04/11 14:23:20 | at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
com.company.smx.data.mobile.utils.beans.Class3.lambda$method1(Class3.java:117)
这是伪代码的第三个方法,第一个和第二个,我需要知道
UPD
我通过 REST API 调用我的第一个方法,所以它看起来像
public interface RestService {
@GET
@Produces("application/json; charset=utf-8")
@Path(value = "/rest/method1")
ResultResponse method1 (@PathParam("id") String id);
}
public class RestServiceImpl implements RestService {
method1_1(String id){
method2();
}
//and other pseudo code
}
正如我之前所说,在@Common Man 的帮助下,我可以找到直到第三种方法的唯一方法,因为在那之后我只有
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
static void printLongerTrace(Throwable t){
for(StackTraceElement e: t.getStackTrace())
System.out.println(e);
}
这将打印 Stacktrace 的每一行,不会有 12...more
这很可能不是答案,但值得一看:https://coderanch.com/t/442321/java/full-stacktrace
我有一个意外错误,它创建了包含很多行和内部不同库的 stackTrace。如果从上到下阅读它,可能会看到除了 2-3 第一个方法之外的每个被调用的方法。看起来像
//Pseudo code
method1_1(){
method2();
}
method1_2(){
method2();
}
method1_3(){
method2();
}
method2(){
method3();
}
method3(){
method4();
}
method4(){
method5();
}
method5(){
method6();
}
StackTrace 只显示了 3-6 个方法,但没有显示第二个,第一个中的哪个调用了第二个?我怎么知道呢?该程序很大,日志每 0,1-0,001 秒写入一次。这就是为什么对每种方法都进行日志记录并不好。我无法对错误建模,它只会发生。我需要知道什么方法会引发该错误。示例中有 6 个 first 方法,但还有更多。
P.S. 跟踪看起来像那样
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.dao.impl.UserDaoServiceImpl.updateUser(UserDaoServiceImpl.java:418)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.dao.impl.UserDaoServiceImpl$$FastClassBySpringCGLIB$32584e.invoke(<generated>)
INFO | 2019/04/11 14:23:20 | at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
INFO | 2019/04/11 14:23:20 | at org.springframework.transaction.interceptor.TransactionInterceptor.proceedWithInvocation(TransactionInterceptor.java:96)
INFO | 2019/04/11 14:23:20 | at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
INFO | 2019/04/11 14:23:20 | at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.dao.impl.UserDaoServiceImpl$$EnhancerBySpringCGLIB$$c376b217.updateUser(<generated>)
INFO | 2019/04/11 14:23:20 | at sun.reflect.GeneratedMethodAccessor936.invoke(Unknown Source)
INFO | 2019/04/11 14:23:20 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
INFO | 2019/04/11 14:23:20 | at java.lang.reflect.Method.invoke(Method.java:498)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
INFO | 2019/04/11 14:23:20 | at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
INFO | 2019/04/11 14:23:20 | at com.sun.proxy.$Proxy564.updateUser(Unknown Source)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.mobile.utils.Class2.method3(Class2.java:58)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.mobile.utils.beans.Class3.method2(Class3.java:177)
INFO | 2019/04/11 14:23:20 | at com.company.smx.data.mobile.utils.beans.Class3.lambda$method1(Class3.java:117)
INFO | 2019/04/11 14:23:20 | at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
INFO | 2019/04/11 14:23:20 | at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
INFO | 2019/04/11 14:23:20 | at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
INFO | 2019/04/11 14:23:20 | at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
INFO | 2019/04/11 14:23:20 | at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
com.company.smx.data.mobile.utils.beans.Class3.lambda$method1(Class3.java:117)
这是伪代码的第三个方法,第一个和第二个,我需要知道
UPD 我通过 REST API 调用我的第一个方法,所以它看起来像
public interface RestService {
@GET
@Produces("application/json; charset=utf-8")
@Path(value = "/rest/method1")
ResultResponse method1 (@PathParam("id") String id);
}
public class RestServiceImpl implements RestService {
method1_1(String id){
method2();
}
//and other pseudo code
}
正如我之前所说,在@Common Man 的帮助下,我可以找到直到第三种方法的唯一方法,因为在那之后我只有
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
static void printLongerTrace(Throwable t){
for(StackTraceElement e: t.getStackTrace())
System.out.println(e);
}
这将打印 Stacktrace 的每一行,不会有 12...more
这很可能不是答案,但值得一看:https://coderanch.com/t/442321/java/full-stacktrace