Micronaut:正确记录“未接收”不出现在System.err上的例外

发布于 2025-01-23 03:42:13 字数 1020 浏览 1 评论 0原文

我有一个有关捕获“未被发生”例外的问题,该异常出现在system.err绕过日志记录配置上:所有其他日志消息都在system.out(在我的情况下是JSON-FORMATT的)。但这并没有发生异常和堆叠轨迹“已记录”到system.err!

我已经意识到这种情况至少在两种情况下发生:

  • 通过executorService (如“计划任务”章)。我已经在方法中添加了@retryable注释;但是在所有重试失败后,最后一次失败重试的“最终”异常出现在system.err及其堆栈跟踪(其他较早失败的恢复效果do not ) ,似乎它们被引擎盖下的重试的“机制”捕获。
  • 除了失败的健康指标(通过子类avctracthealthedicator)实现的例外(它们是实现的)。

我已经尝试实现自己的taskexceptionHandler,替换默认一个(在”计划任务“章);和/或通过System.Seter.seterr(System.out)main方法中构建/设置Micronaut应用程序上下文之前。但是我的测试案例证明,似乎没有任何帮助。

我是否错过了Micronaut文档中的一章? 感谢您的提示。

关于

基督徒

I've a question regarding capture of "uncaught" exceptions, which appears with stack trace on System.err, circumventing logging configuration: All the other log messages appear properly formatted on System.out (JSON-formatted in my case). But this doesn't happen with Exceptions and stack traces "logged" to System.err!

I've recognized this to happen under at least two circumstances:

  • Asynchronous execution of tasks (HTTP requests in my case) via ExecutorService (as mentioned in "Scheduled Tasks" chapter). I've added @Retryable annotation to the method; but after all retries fail, "final" Exception thrown by last unsuccessful retry appears on System.err with its stack trace (the other ones thrown by earlier failed retries do not appear, seems they are caught by retry "mechanism" under the hood).
  • With Exceptions thrown by failed Health indicators (they are implemented by subclassing AbstractHealthIndicator).

I've tried implementing my own TaskExceptionHandler, replacing the default one (also mentioned in "Scheduled Tasks" chapter); and/or by adding System.setErr(System.out) in main method before building/setup of Micronaut Application Context. But nothing seems to help as my test cases attest.

Have I missed a chapter in Micronaut's documentation?
Thanks for any hints.

Regards

Christian

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

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

发布评论

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

评论(1

话少情深 2025-01-30 03:42:13

我的赌注是,Micronaut不提供为设定全球未知的异常处理程序的工具,因为这是由更广泛的JRE支配的。我们已经通过 thread> thread.thread.html#setDefaultuncectexceptionhandler

Thread.setDefaultUncaughtExceptionHandler((t, e) -> logger.error("Uncaught exception", e));

My wager is that Micronaut doesn't provide tools for setting a global uncaught exception handler because that's governed by the wider JRE. We've solved the problem in a few of our services with Thread.html#setDefaultUncaughtExceptionHandler by doing something like this at application startup:

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