如何在 grails 中记录 stackTrace 而不引发异常

发布于 2024-10-06 22:23:23 字数 167 浏览 0 评论 0原文

在某些情况下,我想捕获异常,但仍然在通过 grails 中的 Log4J 属性定义的 stackTrace 日志中显示堆栈跟踪。我怎样才能做到这一点?

例如,我知道我可以使用 log.error myException.stackTrace 将其写入“正常”日志,但我不希望堆栈跟踪填满我的正常日志文件。

In certain situations, I'd like to catch an Exception but still show the Stack Trace in the stackTrace log defined via the Log4J properties in grails. How can I do that?

I know I could write it into the "normal" log using log.error myException.stackTrace for example, but I don't want the stack trace to fill up my normal log file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

嘦怹 2024-10-13 22:23:23

已经有一个由 grails 生成的堆栈跟踪日志。

您可以获取该记录器,然后在异常的 catch 块中添加日志语句

LogManager.getLogger("StackTrace")

http://grails.org/doc/latest/guide/3.%20Configuration.html#3.1.2%20Logging

there is already a stacktrace log generated by grails.

you can get that logger and then add your log statements in the catch block of the exception

LogManager.getLogger("StackTrace")

http://grails.org/doc/latest/guide/3.%20Configuration.html#3.1.2%20Logging

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