How to use log4j's FileAppenders asynchronously?

不问归期 提交于 2019-12-09 04:44:59

问题


I work on a low-latency trading application. We'd like to increase the amount of lof4j logging that we write to file, whilst minimising the impact on our end-to-end processing time.

What is the recommended way of doing this? I think FileAppender.append is synchronous, so we need to do something a bit smarter than that....


回答1:


Yes, the appenders are synchronous. You want something like this:

http://www.spartanjava.com/2009/asynchronous-logging-with-log4j/




回答2:


bear in mind that AsyncAppender adds a thread per appender & that increasing the amount of logging you do may mean a substantial increase in the amount of string concatentation going on which often means a substantial amount of string processing/munging/formatting which can be pretty expensive (relative to the latency involved in a low latency trading app anyway).




回答3:


If you need to log from a multithreaded application slf4j and its implementation logback are much better choice.



来源:https://stackoverflow.com/questions/4957319/how-to-use-log4js-fileappenders-asynchronously

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