How to use log4j's FileAppenders asynchronousl

2019-03-16 06:32发布

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....

标签: java log4j
3条回答
干净又极端
2楼-- · 2019-03-16 07:08

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

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

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-03-16 07:18

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

查看更多
该账号已被封号
4楼-- · 2019-03-16 07:22

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).

查看更多
登录 后发表回答