简体   繁体   English

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

[英]A good database log appender for Java?

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). 在我的工作场所,我们编写了一个自定义log4j appender,它将日志消息写入数据库(异步使用专用线程,因此没有性能损失)。 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)? 是否有一个开源解决方案来执行此操作(特别是对于log4j或任何其他java记录器)?

Some things that our appender has, and I would like to see in an alternative: 我们的appender有一些东西,我希望在另一种方法中看到:

  • 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. 我们的appender支持以下列,我希望在我们找到的任何解决方案中看到所有这些列。

  • LogId LOGID
  • Time 时间
  • message 信息
  • stacktrace 堆栈跟踪
  • process id 进程ID
  • thread id 线程ID
  • machine name 机器名称
  • component 零件
  • Level (debug/info/warn/...) 等级(调试/信息/警告/ ...)
  • ThreadName ThreadName

There is also a DBAppender class provided by log4j (log4j requires a specific set of tables to log using this appender). log4j还提供了一个DBAppender类(log4j需要一组特定的表来使用此appender进行记录)。 http://logging.apache.org/log4j/companions/receivers/apidocs/org/apache/log4j/db/DBAppender.html 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 这里有一个更新的非Apache jdbc记录器,您可能还想尝试: http//www.dankomannhaupt.de/projects/index.html

Just curious, wouldn't it severely affect the performance of an application hosting such appender? 只是好奇,难道不会严重影响托管此类appender的应用程序的性能吗? Logging directly into relational database is quite costly even when you do it asynchronously. 即使您异步执行,直接登录到关系数据库也是非常昂贵的。

You don't need a custom appender for LOG4J to write to databases. LOG4J不需要自定义appender来写入数据库。 You can use JDBCAppender bundled with Apache's distribution. 您可以使用与Apache的发行捆绑在一起的JDBCAppender

According to APACHE's documentation, this API could be replaced in the future. 根据APACHE的文档,此API可能在将来被替换。 But for now, we use it and it works very well. 但就目前而言,我们使用它并且效果非常好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM