SLF4J 日志记录到文件 vs. DB vs. Solr

发布于 2025-01-01 05:16:34 字数 321 浏览 2 评论 0原文

我需要一些关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅笑轻吟梦一曲 2025-01-08 05:16:34

考虑放弃 log4j 并使用 slf4j API 的 logback 实现
Logback 有一个广泛的可用appenders 列表。

我认为也许您的问题更多的是关于使您的日志可搜索。答案取决于您要搜索的内容。

  • 对于简单的应用程序,我只需使用滚动文件附加程序并 grep 查找我感兴趣的消息。
  • 更复杂的应用程序还会将消息另外记录到数据库中。
  • 目前没有可用于 log4j 和 logback 的 Solr 附加程序。然而,使用 solrj API 应该很容易编写
  • 用于监视日志消息,有一个 lilith 这是日志消息的远程 GUI。
    不知道它的扩展性如何,但对于演示和简单的监控来说它确实很有趣。

更新

正如 Sebastien 所建议的,还有一个用于 logback 的 Graylog2 附加程序。现在可在 Maven Central 中使用

<dependency>
    <groupId>me.moocar</groupId>
    <artifactId>logback-gelf</artifactId>
    <version>0.9.6p2</version>
</dependency>

当然,这取决于是否安装了 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.

  • For simple applications I just use a rolling file appender and grep this for the messages I'm interested in.
  • More complicated applications will additionally log messages to the database.
  • There is currently no Solr appender available for log4j and logback. It should however be easy to write using the solrj API
  • For monitoring log messages there is a lilith which is a remote GUI for log messages.
    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

<dependency>
    <groupId>me.moocar</groupId>
    <artifactId>logback-gelf</artifactId>
    <version>0.9.6p2</version>
</dependency>

Of course this will depend on having a graylog2 server installed.

无风消散 2025-01-08 05:16:34

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文