如何在 grails 中记录 stackTrace 而不引发异常
在某些情况下,我想捕获异常,但仍然在通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已经有一个由 grails 生成的堆栈跟踪日志。
您可以获取该记录器,然后在异常的 catch 块中添加日志语句
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
http://grails.org/doc/latest/guide/3.%20Configuration.html#3.1.2%20Logging