java web:如何将未捕获的异常的堆栈跟踪重定向到日志文件?
我只想将未捕获的异常的堆栈跟踪从控制台重定向到日志文件。其余的内容应该像往常一样出现在控制台上。
I want to redirect only stacktrace of uncaught exception from console to log file. The rest of the things should appear on console as usual.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置< /a> a
Thread.UncaughtExceptionHandler
打印到所需的文件。printStackTrace
是线程安全的,因此多个线程可以共享同一个PrintStream
。Set a
Thread.UncaughtExceptionHandler
that prints to the desired file.printStackTrace
is threadsafe, so several threads may share the samePrintStream
.为此创建了一个示例程序,感谢 gustafc
输出是
Created a sample program for this, Thanx to gustafc
Output is