Wednesday, December 18, 2013

Alternate way of connecting log4j to database

There is always difference between production server and development server at local PC. Take for an example on the audit trail module, this module provides audit service to an application. And this service will redirect the log4j logging activity to a database rather than storing logs to a file. The codes in SVN will always adhere to the configuration on production server, and this is how log4j configuration looks like:
log4j.appender.SEC = org.huahsin.JDBCConnectionPoolAppender
log4j.appender.SEC.jndiName = jdbc/myDatasource
If I don’t have the data source being configure at my local server (I’m using WebSphere Application Server Liberty Profile), executing that code will cause the server complaining this error:
[err] javax.naming.NameNotFoundException: jdbc/myDatasource
[err]     at com.ibm.ws.jndi.internal.ContextNode.lookup(ContextNode.java:242)
[err]     at [internal classes]
This isn’t that bad actually, if I insist choose not to configure data source at my local server, following changes need to be done in log4j configuration file:
log4j.appender.SEC=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.SEC.URL=jdbc:informix-sqli://xxx.xxx.xxx.xxx:2020/csdb:INFORMIXSERVER=online
log4j.appender.SEC.driver=com.informix.jdbc.IfxDriver
log4j.appender.SEC.user=xxx
log4j.appender.SEC.password=xxx

No comments: