问题描述
我有一个来自Tomcat的日志文件,该文件显示以下错误:
I have a logfile from Tomcat which shows the following error:
Caused by: java.lang.ClassNotFoundException: com.package.MyClass
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1858)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1709)
... 33 more
Stacktrace的上部(删除了原因之前的所有内容,因为它没有显示我需要的信息)仅显示了Spring内部类.但是,出现此错误是因为有人忘记报告war文件的传递依赖...
The upper part of the Stacktrace (removed everything before the cause because it doesn't show the information I need) only shows Spring-internal classes. However, this error comes because someone forgot to report a transitive dependency for the war file...
是否可以通过 配置Tomcat 来显示隐藏的stacktrace行?
Is there a way to configure Tomcat to show the hidden stacktrace lines?
注意:exception.getCause().printStacktrace()
不是我想要的,我希望所有堆栈跟踪都详细打印.
Note: exception.getCause().printStacktrace()
is not what I am looking for, I want all stacktraces to be printed in detail.
推荐答案
真的不知道如何在Tomcat中进行配置,但是,如果在初始化Spring Servlet时发生错误,则可以对其进行扩展并输出异常手动:
Don't really know how to configure it in Tomcat but, if the error is something that happens when initializing the Spring Servlet you can extend it and print the exception manually:
public class StartupErrorSafeDispatcherServlet extends DispatcherServlet {
private Logger logger = ...
@Override
public void init(ServletConfig config) throws ServletException {
try {
super.init(config);
} catch (Throwable t) {
System.out.println(ExceptionUtils.getStackTrace(t));
logger.error("{}", ExceptionUtils.getStackTrace(t));
}
}
}
这篇关于如何在日志文件中显示异常原因的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!