logback FileAppender -> AsyncAppender 刷新信号
logback FileAppender -> AsyncAppender flush signal
我正在使用附加到 AsyncAppender 的 FileAppender 的本地变体。我正在为每个写入线程创建一个 FileAppender。我注意到当我的线程停止时(在 运行() 中的 while 循环结束),FileAppender 的缓冲区中仍有数据。
sl4fj/logback 中的写入线程如何向 Appender 发出信号表明它现在已完成并且 Appender 应该刷新?
谢谢
听起来您有两个可能的隐瞒事件来源:
- AsyncAppender
- FileAppender
根据日志文档,您可以强制 FileAppender 立即刷新:
<immediateFlush>true</immediateFlush>
根据文档,AsyncAppender 将刷新……
Upon application shutdown or redeploy, AsyncAppender must be stopped in order to stop and reclaim the worker thread and to flush the logging events from the queue. This can be achieved by stopping the LoggerContext which will close all appenders, including any AsyncAppender instances. AsyncAppender will wait for the worker thread to flush up to the timeout specified in maxFlushTime. If you find that queued events are being discarded during close of the LoggerContext, you may need to increase the time out. Specifying a value of 0 for maxFlushTime will force the AsyncAppender to wait for all queued events to be flushed before returning from the stop method.
只要 (a) 您正在停止 LoggerContext 并且 (b) 您的未决事件可以在 maxFlushTime 指定的超时时间内刷新,那么您就不会丢失任何事件。
但是,当然,您看到的是遗留的数据,所以……
- 如果数据留在 AsyncAppender 中,那么只需确保您正在关闭 LoggingContext(您可以使用 shutdown hook 来确保发生这种情况)
- 如果数据留在您自己开发的 FileAppender 变体中,那么请考虑向您的 appender 添加等效于 logback 的
immediateFlush
功能。
我正在使用附加到 AsyncAppender 的 FileAppender 的本地变体。我正在为每个写入线程创建一个 FileAppender。我注意到当我的线程停止时(在 运行() 中的 while 循环结束),FileAppender 的缓冲区中仍有数据。
sl4fj/logback 中的写入线程如何向 Appender 发出信号表明它现在已完成并且 Appender 应该刷新?
谢谢
听起来您有两个可能的隐瞒事件来源:
- AsyncAppender
- FileAppender
根据日志文档,您可以强制 FileAppender 立即刷新:
<immediateFlush>true</immediateFlush>
根据文档,AsyncAppender 将刷新……
Upon application shutdown or redeploy, AsyncAppender must be stopped in order to stop and reclaim the worker thread and to flush the logging events from the queue. This can be achieved by stopping the LoggerContext which will close all appenders, including any AsyncAppender instances. AsyncAppender will wait for the worker thread to flush up to the timeout specified in maxFlushTime. If you find that queued events are being discarded during close of the LoggerContext, you may need to increase the time out. Specifying a value of 0 for maxFlushTime will force the AsyncAppender to wait for all queued events to be flushed before returning from the stop method.
只要 (a) 您正在停止 LoggerContext 并且 (b) 您的未决事件可以在 maxFlushTime 指定的超时时间内刷新,那么您就不会丢失任何事件。
但是,当然,您看到的是遗留的数据,所以……
- 如果数据留在 AsyncAppender 中,那么只需确保您正在关闭 LoggingContext(您可以使用 shutdown hook 来确保发生这种情况)
- 如果数据留在您自己开发的 FileAppender 变体中,那么请考虑向您的 appender 添加等效于 logback 的
immediateFlush
功能。