Posted By:
sanghamitra_Chowdhury
Posted On:
Sunday, July 22, 2007 11:46 PM
I am trying to use the JDBCAppender (log4j 1.2.8) in an application to log to a database table. The application already uses log4j to write to a file using a properties file, a fragment is shown below. log4j.appender.APP1=org.apache.log4j.RollingFileAppender log4j.appender.APP1.layout=org.apache.log4j.PatternLayout log4j.appender.APP1.layout.ConversionPattern=%d{z dd MMM yyyy HH:mm:ss}, [%t] ,%-5p, %-20.40c{1}, - %m%n log4j.appender.APP1.file=${catalina.home}/logs/APP1ws.log log4j.appender.APP1.append=true log4j.appender.APP1.immediateFlush=true log4j.appendar.APP1.encoding=UTF-8 log4j.appender.APP1.maxFileSize=10MB log4j.appender.APP1.maxBackupIndex=10
More>>
I am trying to use the JDBCAppender (log4j 1.2.8) in an application to log to a database table. The application already uses log4j to write to a file using a properties file, a fragment is shown below.
log4j.appender.APP1=org.apache.log4j.RollingFileAppender
log4j.appender.APP1.layout=org.apache.log4j.PatternLayout
log4j.appender.APP1.layout.ConversionPattern=%d{z dd MMM yyyy HH:mm:ss}, [%t] ,%-5p, %-20.40c{1}, - %m%n
log4j.appender.APP1.file=${catalina.home}/logs/APP1ws.log
log4j.appender.APP1.append=true
log4j.appender.APP1.immediateFlush=true
log4j.appendar.APP1.encoding=UTF-8
log4j.appender.APP1.maxFileSize=10MB
log4j.appender.APP1.maxBackupIndex=10
For the JDBCAppender, I need to do it programmatically. For the class that needs to use a JDBCAppender, I have used the following code. I have extended the JDBCAppender class to create a class called AppDBAppender.
private Logger logger = Logger.getLogger(this.getClass().getName() );
private AppDBAppender dbAppender = null;
logger.addAppender(new AppDBAppender(cc));
dbAppender = (AppDBAppender) logger.getAppender("DB");
dbAppender.setAppenderProperties();
In the AppDBAppender class, the constructor is
public AppDBAppender(Company cc)
{
super();
this.setName("DB");
}
In the AppDBAppender, I have overwritten the getConnection method to use a Connection from the application Connection Pool. In the AppDBAppender.setAppenderProperties, the code is the following.
public void setAppenderProperties()
{
getConnection();
this.setSql(initialSqlStatement);
}
Please could someone point me at any code samples where the JDBCAppender is added programmatically and used without .properties files?
<<Less