在 printStackTrace() 上打印完整的调用堆栈? [英] Print full call stack on printStackTrace()?

查看:35
本文介绍了在 printStackTrace() 上打印完整的调用堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个小的日志分析器应用程序来处理由我的项目中使用的第 3 方闭源库(内部有自定义记录器)生成的一些日志文件.

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.

如果日志中出现异常条目,我需要沿堆栈跟踪从顶部到异常的实际位置收集有关所涉及方法的汇总信息.

In case of an exception entry in the log I need to collect aggregated information about the methods involved along the stack trace from the top to the actual place of the exception.

不幸的是,默认情况下,Java printStackTrace() 不会打印调用堆栈中的每个方法,而是打印到一定数量的方法,其余的只是作为 16 more... 引用.

Unfortunately, by default Java printStackTrace() does not print every method in the call stack but up to a certain number and the rest is just referenced as 16 more....

如果我可以自己捕获异常,我会使用 getStackTrace() 并自己打印它,但根本原因永远不会包含在这个库抛出的异常中.

If I could catch the exception myself I would use the getStackTrace() and print it myself but the root cause is never included in the exception this library throws.

有没有办法让Java在stacktrace中打印整个调用栈?

除了我的情况外,常见的日志框架是否有这个选项?

该程序在 Sun 的 JVM 上使用 JDK 1.5.0_09 运行.没有办法改变这一点.

The program runs on Sun's JVM with JDK 1.5.0_09. No option to change that.

推荐答案

here is an description 'caused by' 和 '... n more' 打印轨迹中的行.另请参阅 用于 printStackTrace 的 JavaDoc.您可能没有任何工作要做.

here is an explanation of the 'caused by' and '... n more' lines in the printed trace. see also the JavaDoc for printStackTrace. you might not have any work to do.

注意包含字符..."的行的存在.这些行表示此异常的堆栈跟踪的其余部分与由此异常(封闭"异常)引起的异常的堆栈跟踪底部的指示帧数相匹配.这种速记可以大大减少输出的长度,在常见情况下,从与捕获原因异常"的方法相同的方法抛出包装异常.

Note the presence of lines containing the characters "...". These lines indicate that the remainder of the stack trace for this exception matches the indicated number of frames from the bottom of the stack trace of the exception that was caused by this exception (the "enclosing" exception). This shorthand can greatly reduce the length of the output in the common case where a wrapped exception is thrown from same method as the "causative exception" is caught.

这篇关于在 printStackTrace() 上打印完整的调用堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆