Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log to a database using log4j

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?

like image 282
Daniel Moura Avatar asked Sep 01 '09 19:09

Daniel Moura


People also ask

How does log4j logging work?

Log4j allows logged messages to contain format strings that reference external information through the Java Naming and Directory Interface (JNDI). This allows information to be remotely retrieved across a variety of protocols, including the Lightweight Directory Access Protocol (LDAP).

Where does log4j log to?

The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.

Does logging use log4j?

log4j is a reliable, fast and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License. log4j is a popular logging package written in Java. log4j has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages.


2 Answers

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.

like image 198
Ceki Avatar answered Nov 14 '22 03:11

Ceki


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.

like image 26
Yishai Avatar answered Nov 14 '22 03:11

Yishai