LogHandler 刷新与发布中的直接输出

发布于 2024-11-24 14:58:33 字数 730 浏览 2 评论 0原文

我目前正在编写自己的 java.util.logging.Handler,但我不太理解其中的概念...... 我在这里有我的发布方法,其中包含查看是否应显示 LogRecordFormatter (或者如果 SimpleFormatter >.getFormatter() == null),最后我将格式化的字符串放入缓存中。

现在我写了flush()方法,但我在这里遇到了麻烦:Java永远不会调用flush()方法,所以当发生错误时,它不会显示。我将 flush() 调用放入我的 publish() 方法中,现在我可以看到日志消息...所以我在这里看不到概念?何时应该调用flush()以及由谁调用?或者我是否必须像现在一样,在publish()方法中自己调用flush()

如果您查看以下示例:http://www.java2s。 com/Code/Java/Language-Basics/HowtowritecustomLoghandler.htm 他们甚至不使用 flush() 方法

I'm currently writing an own java.util.logging.Handler, and I dont really understand the concept there...
I have my publish method here which contains the logic to see if a LogRecord should be shown, a Formatter (or just SimpleFormatter if the .getFormatter() == null) and finally i put the formatted String into a Cache.

Now i wrote the flush() Method and I'm getting in trouble here: The flush() Method is never called by Java, so when an Error occured, its not shown. I put a call of flush() into my publish() Method and now i can see the log messages... So i dont see the conecept here? When should flush() called and by whom? Or do I have to make it like i do it now, and call flush() by my own in the publish() Method?

If you take a look to this example: http://www.java2s.com/Code/Java/Language-Basics/HowtowritecustomLoghandler.htm they dont even to anything with the flush() Method

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

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

发布评论

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

评论(1

寄离 2024-12-01 14:58:33

现在可能有点晚了,但为了其他人的利益......

我看到了类似的东西,并假设了与你类似的行为

我查看了它的用法,这似乎是一种以标准方式进行冲洗的方法,并且似乎保证你会在关闭时被冲得更厉害。

有些人“冲洗自己”,我想保证超类也可以从冲洗中受益。

最后,由于此刷新没有阈值控制,而且我没有看到它在调试会话中被调用,或者调用它的代码,我认为 Java 在这方面没有给我们任何东西。

Probably a bit late now but for the benefit of others...

Im seeing something similar, and assumed similar behaviour to you

I had a look at the usages of it and it seems to be a way to do a flush in a standard way, and seems to be guarantee you will be flushed on close more than anything.

Some people "flush themselves", I suppose guaranteeing that superclasses can benefit from the flush as well also.

Finally since there is no threshold control on this flush and since Im not seeing it being called in debug sessions, or code to call it I don't think Java gives us anything in this regard.

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