Log4j JDBCAppender

While searching for a Log4j appender that is capable of logging into a relational database, I first tried the org.apache.log4j.jdbc.JDBCAppender that ships with the Log4j distribution. Unfortunately, that one was not able to process logging messages that had characters like ' (single quote) and , (comma) in it, because of its simple nature. Looking further, I noticed an alternative JDBCAppender package from Thomas Fenner (Page empty). By providing interfaces for connection handling, table and column access and other goodies, it was able to log arbitrary messages. However, the version provided did not initially work with J2SE SDK 1.4 and the current Log4j version 1.2.9. After fixing the problems, the JDBCAppender works fine in our current project at arvato systems. I also changed the package names form com.klopotek.utils.log to org.apache.log4j.jdbcplus. The result is available to the public here.

Note: Log4j project will release a new DbAppender with their upcoming release. This appender logs into a set of 3 tables with predefined columns that must exist in the database. Table names are logging_event, logging_event_property and logging_event_exception. If that is what you like, you might want to use the DbAppender.

Main Features of this JDBCAppender in Comparision to org.apache.log4j.jdbc.JDBCAppender / org.apache.log4j.db.DbAppender Missing Features, Problems License

JDBCAppender is distributed under the Apache 2.0 license. Use the following at your own risk. Backup and test before using it in production environment.

Download and Links

Note: Testcases are tested on Firebird 1.5 and partly on MySQL 4.0.10.

The software is provided "as is". Please contact me directly if there are any bugs, problems or missing features. Please use the term JDBCAppender in the subject of your e-mail. However, I might not be able to fix or enhance anything. The forum is currently closed. I hope to reopen project development at SourceForge again sometime. Note: System parameter -Dlog4j.configDebug=true switches on internal Log4J logging which may help in some cases to find the cause of a problem.

 Monitor page for changes 

it's private    by ChangeDetection


Please use the latest version. If there is any problem with the latest version, please let me know and try with another release. Since v2.1.01 from 2005-06-05, versions are numbered. jdbcappender.jar/META-INF/MANIFEST.MF contains the version number of each release.

Version Date Comment Thanks To Download
2.1.01 2005-06-05 Introduced basic versioning as requested by users. ParameterMetaData fix for different Oracle versions. ORACLE_SEQUENCE bug fix Jürgen Schmied, Waldemar Kaus here
none 2005-05-15 Oracle Fix. Connection loss fix. Jürgen Schmied, Jürgen Dufner here
none 2005-02-06 Fixed some issues if buffer size > 1. Do not execute SQL statement if it is empty. Patrick Carlos, Jürgen Dufner here
none 2004-12-23 Enabled Stored Procedure logging on Oracle. Fixed large Throwable problem - new throwableMaxChars property. Fixed MDC issue. here
none 2004-08-22 Enabled Stored Procedure logging (requires J2SDK 1.4) - thanks to Richard Ingle for the suggestion. Pattern delimiter may now be longer than one character (requires J2SDK 1.4). Supports empty passwords. Richard Ingle, Seth Plough here
none 2004-07-11 Accepts empty passwords. New integer priority wildcard @IPRIO@ Bavo De Ridder here
none 2004-05-23 PreparedStatement support. Supports @LAYOUT@ without parameter. here
none 2004-05-05 Should solve NullPointer in freeConnection. here
none 2004-04-25 Manages broken database connections. Follows guideline to use errorHandler only to output errors. Includes Apache License 2.0 here
none 2004-04-15 Replaced @LAYOUT_MSG@ and @LAYOUT_x@ wildcards with a more general @LAYOUT:x@ mechanism with configurable .layoutPartsDelimiter. @LAYOUT_MSG@ has to be replaced by @LAYOUT:1@ if upgrading from earlier versions. here
none 2004-04-07 No longer sets ' delimiters by default, can be done in SQL statements. New attribute "quoteReplace" to control whether single quotes ' are replaced by 2 single quotes ''. See example. commit option takes 'true'/'false' parameter instead of 'Y'. Enables usage of alternative Layouts. here
none 2004-03-21 Supports more than one patternLayout column with sql wildcards @LAYOUT_1/2/3@ and configuration keys layout1/2/3. See example. Fixes problems with special time/date format and others. here
none 2004-03-21 Now supports J2SDK 1.3, 1.4 and 1.5. here
none 2004-03-07 Apache license added. here
none 2003-11-30 new: @MDC:key@ supporting Mapped Diagnostic Contexts for a given key. MDC for configuration 2c) not yet tested. I am aware of problems using @TIMESTAMP@ on different databases, but do not know a quick fix. Prepared statements would solve it, but are not easy to implement. here
none 2003-10-19 @MSG@ no longer required. freeConnection() missing in one place. Observe commit configuration parameter - should fix JBoss managed transaction issue. Enabled use of @NDC@ (nested diagnostic context). Richard Porter, Samual Solon here
none 2005-09-18 Fix for current Oracle driver to avoid ORA-00936 when configuring table. Enabled use of @MSG@ (non-layouted msg) and @LAYOUT_MSG@ (layouted message). Separation was necessary to fix issue of missing Throwable information in distributed applications. New configuration parameter "dbclass". Uwe Hoell, Thomas Svenson here
none 2003-09-03 Bug fix for IBM DB2 UDB. Improved error handling to avoid java.sql.SQLException: ORA-01000: maximum open cursors exceeded. here
none 2003-05-28 Updated and successfully tested Oracle examples. Bug fix in quote ['] escape. here
none 2003-05-18 @THROWABLE@ is supported as wildcard in SQL statements. Corrected error handling in JDBCAppender to support FallbackErrorHandler. here
none 2003-04-16 JDBCLogger escapes single quote ['] in log messages, priority, thread and category names by default with double single quote ['']. That should work for most databases. John -
none 2003-04-11 Refactoring in JDBCLogger (Thanks Donald). Enabled use of @TIMESTAMP@ in sql statements (Thanks for asking, Ron). Bug fix in JDBCAppender.close() (Thanks, Waldo). A few new tests. Donald, Ron, Waldo here
none 2003-01-17 Discovered and fixed bug if default connection handler is used. New example in property-file. Eoin Andrew O'Kane here
none 2002-12-12 Re-release of this JDBC appender based on Thomas Fenner's implementation. -

Copyright © 2007 Danko Mannhaupt. Alle Rechte vorbehalten.  Rechtliche Hinweise. Rahmen einblenden