是否有 Log4J 布局/格式化程序可以修剪堆栈跟踪以查找异常?

发布于 2024-07-19 07:50:14 字数 225 浏览 3 评论 0原文

我正在寻找一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

烟火散人牵绊 2024-07-26 07:50:14

我问了一个类似的问题(关于完全抑制不幸

的是,没有相应的设置,您需要子类化 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.

山田美奈子 2024-07-26 07:50:14

我也尝试寻找这个,但没有找到任何令人满意的东西,所以我编写了一个自定义 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.

霞映澄塘 2024-07-26 07:50:14

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.

终止放荡 2024-07-26 07:50:14

有三种方法可以做到这一点:

  1. 查找其他人编写的库或代码
  2. 自己编写(扩展/实现)
  3. 使用默认布局,但在将异常堆栈传递给记录器之前修剪异常堆栈

There are three ways to do this:

  1. Find a library or code that someone else did
  2. Write it yourself (extend/implement)
  3. Use the default Layout, but prune the exception's stack before passing it to logger
暮凉 2024-07-26 07:50:14

您可以编写一个具有您需要的特殊逻辑的自定义 Appender。 这可能是一个好方法。

You can write a custom Appender that has the special logic you need. That might be a good way to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文