gpt4 book ai didi

java - 如何获取完整的 stackTrace

转载 作者:行者123 更新时间:2023-12-02 10:00:56 27 4
gpt4 key购买 nike

我遇到了一个意外错误,它创建了包含大量行和不同库的 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 个第一个方法,但还有更多。

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$$8732584e.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$1.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$57(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$57(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

关于java - 如何获取完整的 stackTrace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55638216/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com