许多 Java 应用程序的集中日志记录:Syslog、JMS、Http、本地文件
我希望所有应用程序日志都集中(最好是近乎实时)。我们将使用 Log4 Appender。我应该使用哪一个:
- 在 JMS 队列中发送日志事件
- Syslog / syslog-ng
- 写入本地文件并使用 rsync(每 3 秒)复制日志
- 对集中式 REST Http 服务执行 POST
您使用的是哪一个?
I want all my applications log to be centralized (ideally in near real-time). We will use a Log4 Appender. Which one should I use:
- Send log event in a JMS Queue
- Syslog / syslog-ng
- Write to a localfile and use rsync (every 3second) to replicate the log
- Do a POST to a centralized REST Http Service
Which one are you using?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
取决于您的要求。记录到队列(如 JMS 中)为您提供了最大的灵活性,因为一旦日志消息写入队列,您的日志操作就可以返回。然后,您可以自由地让另一个进程将这些日志消息从队列中取出并将它们写入您首选的日志存储(数据库、文件系统等)。
(轻微的)缺点是您的日志消息将稍微落后于正在记录日志的系统,但情况几乎总是如此,即使使用基于文件的日志记录也是如此。
Depends on your requirements. Logging to a queue (as in JMS) gives you the most flexibility of your options as your log operation can return as soon as the log message has been written to the queue. You are then free to have another process take those log messages off the queue and write them to your preferred logging store (database, file system, ...).
The (slight) downside is your log messages will lag slightly behind the system that is logging, but this is almost always the case, even with file-based logging.
这可能有点过分了,但是您看过 Splunk 吗?对于 Java 应用程序,我使用 Log4J 或 SLF4J 来记录到文件,然后 Splunk 可以聚合日志并使其可搜索。
This may be overkill but have you looked at Splunk? For Java apps, I've used either Log4J or SLF4J to log to files, then Splunk can aggregate the logs and make them searchable.
我不熟悉 Log4(Log4j?),但它有数据库附加程序吗?这将提供您所需的集中化,并消除复制日志的任何需要。
I'm not familiar with Log4 (Log4j?), but does it have a database appender? This would provide the centralization you need and would eliminate any need to replicate your logs.
这实际上很大程度上取决于您想要什么。不过,我认为 syslog 不是应用程序日志记录的好选择,它更适合基础设施日志。在不了解太多细节的情况下,您列出的所有 4 个选项看起来都不错。我们使用这个。
It really very much depends on what you want.. I don't think syslog is a good choice for application logging though, it's more suitable for infrastructure logs. Without knowing too much details, all 4 options you listed look OK. We use this.
顺便说一句,log4j确实有 AsyncAppender 使用队列以及用于记录日志的专用消费者线程
btw, log4j does have AsyncAppender which uses queue and dedicated consumer-thread for logging from it