How does Log42 async logger behaves on sudden shutdown of application?

岁酱吖の 提交于 2021-02-07 10:53:48

问题


For asynchronous logging, what happens to the logs that are not yet written to the destination appender and the application/system goes down? Do we loose these logs (since they are in memory) or is there a way to recover them?

I don't want to loose any ERROR level logging. So my next question is: Is there a way to configure sync and async logging for a single appender at log level? For e.g. I want my file appender to perform ERROR level logging synchronously while INFO/DEBUG asynchronously?

Thanks in advance!


回答1:


If the process dies gracefully, all events in the queue will be processed. See this code for how AsyncLogger shutdown works in detail.

If the process is not allowed to do cleanup (kill -9 for example) then you may lose events. Such is life.

If you want ERROR level log events processed synchronously but other levels asynchronously you may not be able to use AsyncLoggers but you can use AsyncAppender. You can configure the Logger(s) to route to both a FileAppender and an AsyncAppender. The AsyncAppender routes to the FileAppender. Then use Filters to make the AsyncAppender only accept INFO and below, while the FileAppender accepts ERROR and above.



来源:https://stackoverflow.com/questions/44035629/how-does-log42-async-logger-behaves-on-sudden-shutdown-of-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!