正常配置:
log4j.appender.db=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.db.BufferSize=1
#log4j.appender.db.sqlname=dbo
log4j.appender.db.driver=oracle.jdbc.driver.OracleDriver
log4j.appender.db.URL=jdbc\:oracle\:thin\:@127.0.0.1\:1521\:xxx
log4j.appender.db.user=xxx
log4j.appender.db.password=xxx
log4j.appender.db.sql=insert into Sys_Log (Log_Belong_Biz,Log_Belong_Object,Log_Belong_Action,Log_Subject,Log_Detail,Input_User,Input_DateTime) VALUES ('%X{logBelongBiz}','%X{logBelongObject}','%X{logBelongAction}','%X{logSubject}','%X{logDetail}','%X{inputUser}',to_date(substr('%d',0,19),'yyyy-MM-dd hh24:mi:ss'))
log4j.appender.db.layout=org.apache.log4j.PatternLayout
重写JDBCAppend:
log4j.appender.db=Log4jJDBCAppender
log4j.appender.db.BufferSize=1
#log4j.appender.db.sqlname=dbo
log4j.appender.db.sql=insert into Sys_Log (Log_Belong_Biz,Log_Belong_Object,Log_Belong_Action,Log_Subject,Log_Detail,Input_User,Input_DateTime) VALUES ('%X{logBelongBiz}','%X{logBelongObject}','%X{logBelongAction}','%X{logSubject}','%X{logDetail}','%X{inputUser}',to_date(substr('%d',0,19),'yyyy-MM-dd hh24:mi:ss'))
log4j.appender.db.layout=org.apache.log4j.PatternLayout
public class Log4jJDBCAppender extends JDBCAppender {
public final static String USER = ConfigUtility.getConfigValue("/config.properties", "DB_USERNAME");
public final static String PASS = JdbcUtility.getPassword();
public final static String DB_URL = ConfigUtility.getConfigValue("/config.properties", "DB_URL");
public Log4jJDBCAppender(){
databaseURL = DB_URL;
databaseUser = USER;
databasePassword=PASS;
}
}