Log to a database using log4j

27,776

Solution 1

If you are looking for a database appender which not only works, but also supports connection pooling, is maintained and properly documented, than consider logback's DBAppender.

Ironically enough, the warning in the javadocs about removing JDBCAppender in future versions of log4j was written by me.

Solution 2

You can use an alternative appender, but really Log4j 1.2 is going to be around and standard for a long time. They developed DBAppender as part of their receivers companions, which isn't officially released, but you can download the source code and get your own going as well.

Unless the issue of not logging exceptions bothers you, JDBCAppender is just fine. Any further upgrade to 2.0 is going to be more radical than just changing JDBCAppender (if 2.0 happens), so I wouldn't worry about using it, despite the warning. They clearly don't have a solid roadmap or timeline to introducing a new version, and 1.2.15 was released in 2007.

Share:
27,776

Related videos on Youtube

Michel Parmentier
Author by

Michel Parmentier

Updated on July 09, 2022

Comments

  • Michel Parmentier
    Michel Parmentier almost 2 years

    Since in log4j javadoc is

    WARNING: This version of JDBCAppender is very likely to be completely replaced in the future. Moreoever, it does not log exceptions.

    What should I do to log to a database?

  • Rachel
    Rachel about 12 years
    Is this answer still valid after 3 yrs or there are some other database logging framework available?
  • Vincent
    Vincent over 10 years
    I can confirm it is valid, I just used JDBCAppender recently.
  • Kumar
    Kumar over 9 years
    @Vincent I am logging pojo object in the log through JDBCAppender. I would like to insert different pojo object value in the data base through log. HOw to do it? Thanks.