SLF4J 日志记录到文件 vs. DB vs. Solr
我需要一些关于 SLF4J 日志记录的建议。
目前,我们正在为 Java Web 应用程序使用 SLF4J 日志记录(log4j 绑定),该应用程序使用简单的 ConsoleAppender。我们的下一步是研究可以保存日志的地方。
我们的应用程序每天处理大约 100,000 条消息。每条消息生成大约 60 -100 行日志。我们的目标是能够快速搜索和查找失败的消息(使用 messageId)并确定失败的原因。
我的问题是:以下哪个是存储日志的好地方:
- 文件
- DB
- Solr
谢谢。
I need some suggestions in terms of SLF4J logging.
Currently, we are using SLF4J logging (log4j binding) for a our Java web app, which uses the simple ConsoleAppender. Our next step is researching for places where we can save the logs.
Our app processes about 100,000 messages per day. Each message generates about 60 -100 lines of logs. Our goal is to be able to quickly search and find failed messages (using an messageId) and identify causes for the failure.
My question is: which of the following is a good place to store our logs:
- File(s)
- DB
- Solr
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑放弃 log4j 并使用 slf4j API 的 logback 实现
Logback 有一个广泛的可用appenders 列表。
我认为也许您的问题更多的是关于使您的日志可搜索。答案取决于您要搜索的内容。
不知道它的扩展性如何,但对于演示和简单的监控来说它确实很有趣。
更新
正如 Sebastien 所建议的,还有一个用于 logback 的 Graylog2 附加程序。现在可在 Maven Central 中使用
当然,这取决于是否安装了 graylog2 服务器。
Consider switching away from log4j and using the logback implementation of the slf4j API
Logback has an extensive list of appenders available.
I think perhaps your questions is more concerning making your logs searchable. The answer depends on what you're search for.
Don't know how well it scales, but it's certainly interesting for demos and simple monitoring.
Update
As suggested by Sebastien there is also a Graylog2 appender for logback. Now available in Maven Central
Of course this will depend on having a graylog2 server installed.
Servlet 规范中没有提供用于放置日志的文件系统位置的功能。
因此,最稳健、长期的解决方案是简单地使用 java.util.logging(带有 slf4j 绑定)并让 Web 容器处理生成的日志。
您每天大约有 1000 万个日志条目。这意味着您需要小心资源的使用。数据库通信比文件访问昂贵得多。我建议您分析这些方法,看看是否可以获得所需的性能,除了每晚备份的平面文件之外,还需要考虑其他任何事情。
There is no facility in the servlet specification providing you with a file system location for putting logs.
Hence the most robust, long term solution is to simply use java.util.logging (with the slf4j binding) and let the web container handle the logs generated.
You have about 10 million log entries pr day. This mean that you need to be careful with resource usage. Database communication is much more expensive than file access. I would suggest you profile the approaches to see if you can get the performance you need to consider anything else but flat files backed up on a nightly basis.