一个好的 Java 数据库日志附加器?

发布于 2024-10-02 03:13:53 字数 466 浏览 0 评论 0原文

在我的工作场所,我们编写了一个自定义 log4j 附加程序,用于将日志消息写入数据库(异步使用专用线程,因此不会影响性能)。 与写入日志文件相比,我更喜欢它 - 基于数据库的日志更容易查询和分析。

是否有一个开源解决方案可以做到这一点(特别是针对 log4j 或任何其他 java 记录器)?

我们的附加程序具有的一些功能,我希望在替代方案中看到:

  • 日志异常(废话!)
  • 数据库写入来自单独的线程/池

我们的附加程序支持以下列,我希望以任何方式看到它们我们找到的解决方案。

  • LogId
  • 时间
  • 消息
  • 堆栈
  • 跟踪进程 ID
  • 线程 ID
  • 机器名称
  • 组件
  • 级别(调试/信息/警告/...)
  • ThreadName

At my workplace, we wrote a custom log4j appender that writes log messages to the database (uses a dedicated thread asynchronously, so no performance hit).
I prefer it a lot over writing to log files - a database-based log is much more easy to query and analyze.

Is there an open source solution that does this (for log4j specifically, or any other java loggers)?

Some things that our appender has, and I would like to see in an alternative:

  • Logs exceptions (duh!)
  • Database writes are from a separate thread/pool

Our appender supports the following columns, and I would like to see all of them in whatever solution we find.

  • LogId
  • Time
  • message
  • stacktrace
  • process id
  • thread id
  • machine name
  • component
  • Level (debug/info/warn/...)
  • ThreadName

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

你的他你的她 2024-10-09 03:13:54

log4j 还提供了一个 DBAppender 类(log4j 需要一组特定的表才能使用此附加程序进行日志记录)。
http://logging.apache.org /log4j/companions/receivers/apidocs/org/apache/log4j/db/DBAppender.html

这里有一个更新的非 Apache jdbc 记录器,您可能还想尝试一下:
http://www.dankomannhaupt.de/projects/index.html

There is also a DBAppender class provided by log4j (log4j requires a specific set of tables to log using this appender).
http://logging.apache.org/log4j/companions/receivers/apidocs/org/apache/log4j/db/DBAppender.html

There is an updated non-Apache jdbc logger available here you may also want to try:
http://www.dankomannhaupt.de/projects/index.html

没︽人懂的悲伤 2024-10-09 03:13:54

只是好奇,它不会严重影响托管此类附加程序的应用程序的性能吗?即使异步执行,直接登录到关系数据库也是相当昂贵的。

Just curious, wouldn't it severely affect the performance of an application hosting such appender? Logging directly into relational database is quite costly even when you do it asynchronously.

眼中杀气 2024-10-09 03:13:54

您不需要 LOG4J 的自定义附加程序来写入数据库。您可以使用与 Apache 捆绑的 JDBCAppender分配。

根据 APACHE 的文档,该 API 将来可能会被替换。但就目前而言,我们使用它并且效果很好。

You don't need a custom appender for LOG4J to write to databases. You can use JDBCAppender bundled with Apache's distribution.

According to APACHE's documentation, this API could be replaced in the future. But for now, we use it and it works very well.

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