A good database log appender for Java?

2020-02-10 22:22发布

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

3条回答
做自己的国王
2楼-- · 2020-02-10 22:46

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.

查看更多
小情绪 Triste *
3楼-- · 2020-02-10 22:49

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.

查看更多
祖国的老花朵
4楼-- · 2020-02-10 22:53

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

查看更多
登录 后发表回答