log4j:Socket Appender如何工作? [英] log4j: How does a Socket Appender work?

查看:89
本文介绍了log4j:Socket Appender如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定Socket Appender是如何工作的。我知道记录事件被发送到特定端口。然后我们可以在控制台上打印日志或将其放入文件中。

I'm not sure how Socket Appender works. I know that logging events are sent to particular port. Then we can print logs on a console or put into a file.

我的问题更多的是关于日志的发送方式。有没有,例如一个队列?是同步还是异步?可以使用它减慢我的程序?

My question is more about the way logs are sent. Is there e.g. one queue? Is it synchronous or asynchronous? Can using it slow down my program?

我发现了一些信息这里,但我不清楚。

I've found some info here, but it isn't clear for me.

推荐答案

来自SocketAppender文档

From the SocketAppender documentation


记录事件由本机TCP
实现自动缓冲。这意味着如果到服务器的链接很慢但是
仍然比客户端生成的(日志)事件的速度快,
客户端将不会受到慢速网络连接的影响。
但是,如果网络连接比事件
生产的速度慢,那么客户端只能以网络速率进行。特别是
,如果到服务器的网络链接关闭,客户端
将被阻止。

Logging events are automatically buffered by the native TCP implementation. This means that if the link to server is slow but still faster than the rate of (log) event production by the client, the client will not be affected by the slow network connection. However, if the network connection is slower then the rate of event production, then the client can only progress at the network rate. In particular, if the network link to the the server is down, the client will be blocked.

另一方面,如果网络链接已启动,但
服务器已关闭,则在创建log
时不会阻止客户端请求,但由于服务器不可用,日志事件将丢失。

On the other hand, if the network link is up, but the server is down, the client will not be blocked when making log requests but the log events will be lost due to server unavailability.

由于appender使用TCP协议,我会说日志事件是有点同步。

Since the appender uses the TCP protocol, I would say the log events are "sort of synchronous".

基本上,appender使用TCP将第一个日志事件发送到服务器。但是,如果网络延迟太高以至于在生成第二个事件时仍未发送消息,则第二个日志事件将不得不等待(从而阻塞),直到第一个事件被消耗。所以是的,如果应用程序生成日志事件的速度比网络传递的速度快,那么它会降低您的应用程序速度。

Basically, the appender uses TCP to send the first log event to the server. However, if the network latency is so high that the message has still not been sent by the time a second event is generated, then the second log event will have to wait (and thus block), until the first event is consumed. So yes, it would slow down your application, if the app generates log events faster than the network can pass them on.

如@Akhil和@Nikita所述,JMSAppender如果您不希望应用程序的性能受到网络延迟的影响,那么AsyncAppender将是更好的选择。

As mentioned by @Akhil and @Nikita, JMSAppender or AsyncAppender would be better options if you don't want the performance of your application to be impacted by the network latency.

这篇关于log4j:Socket Appender如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆