java 如何异步使用 log4j 的 FileAppenders?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4957319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use log4j's FileAppenders asynchronously?
提问by Phil Harvey
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.
我在开发低延迟交易应用程序。我们希望增加写入文件的 lof4j 日志记录量,同时最大限度地减少对端到端处理时间的影响。
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....
这样做的推荐方法是什么?我认为 FileAppender.append 是同步的,所以我们需要做一些比这更聪明的事情......
回答by Danny Thomas
Yes, the appenders are synchronous. You want something like this:
是的,附加程序是同步的。你想要这样的东西:
http://www.spartanjava.com/2009/asynchronous-logging-with-log4j/
http://www.spartanjava.com/2009/asynchronous-logging-with-log4j/
回答by Matt
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).
请记住,AsyncAppender
为每个 appender 添加一个线程 & 增加您所做的日志记录量可能意味着正在发生的字符串连接量的大幅增加,这通常意味着大量的字符串处理/调整/格式化,这可能非常昂贵(相对于低延迟交易应用程序所涉及的延迟而言)。