是否有 Log4J 布局/格式化程序可以修剪堆栈跟踪以查找异常?
我正在寻找一个 Log4J 布局/格式化程序,它可以帮助我比默认设置更好地修剪异常中的堆栈跟踪。 堆栈执行位于 main() 下面的某个地方是非常明显的,对我来说没有必要知道,而且异常发生在其他一些库的深处,我对此无能为力。
我想要的是一个将堆栈跟踪修剪为我自己的代码中方法的最后 5 个方法调用的布局,通过包含 jar 文件、包或其他内容来标识。
有类似的东西吗,还是我必须自己写一些魔法?
I'm looking for a Log4J Layout/Formatter that helps me prune stack-traces in exceptions a little better than the defaults. That the stack-execution is somewhere below main() is quite obvious and unnecessary for me to know, and that the exception occurred deeply within some other library is really nothing I can do too much about.
What I would like is a Layout that trims the stack-trace to, say the last 5 method-calls of method within my own code, identified by containing jar-file, package or something else.
Is there something along these lines, or do I have to write some magic myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我问了一个类似的问题(关于完全抑制不幸
的是,没有相应的设置,您需要子类化 PatternLayout 来执行此操作。
I asked a similar question (about completely suppressing the stack trace a while back.
Unfortunately, there is no setting for that, you need to subclass PatternLayout to do it.
我也尝试寻找这个,但没有找到任何令人满意的东西,所以我编写了一个自定义 ThrowableRenderer 来修剪无关的堆栈帧。 我已经将代码开源给其他人使用。 查看我的博客文章; 您可以在那里找到代码的链接。
I tried looking for this as well but didn't find anything satisfactory so I wrote up a custom ThrowableRenderer which prunes out extraneous stack frames. I've open sourced the code for others to use. Check out my blog post on it; you can find a link to the code there.
logback-classic(log4j 的后继者)中的“ex”或“Exception”转换字支持打印指定数量的堆栈跟踪行。 “ex”转化词与其余转化词一起记录。 您需要向下滚动一点。
如果您需要有关此主题的更多信息,请联系 logback-user 邮件列表。
The "ex" or "exception" conversion word in logback-classic (log4j's successor) supports printing the specified number of stack trace lines. The "ex" conversion word is documented with the rest of conversion words. You need to scroll down a little.
If you need further information on this topic, please contact the logback-user mailing list.
有三种方法可以做到这一点:
There are three ways to do this:
您可以编写一个具有您需要的特殊逻辑的自定义 Appender。 这可能是一个好方法。
You can write a custom Appender that has the special logic you need. That might be a good way to go.