配置log4j,要向oracle插入一条系统当前时间的sql语句,按网上查找的总是出现各种各样的报错,最后总结出的写法是:
1 ### shezhi### 2 log4j.rootLogger = debug,stdout,D,E,db 3 4 5 log4j.appender.stdout = org.apache.log4j.ConsoleAppender 6 log4j.appender.stdout.Target = System.out 7 log4j.appender.stdout.layout = org.apache.log4j.PatternLayout 8 log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n 9 10 ### 输出info级别以上的信息到E://logs/error.log ### 11 log4j.appender.D = org.apache.log4j.DailyRollingFileAppender 12 log4j.appender.D.File = E://logs/log.log 13 log4j.appender.D.Append = true 14 log4j.appender.D.Threshold = INFO 15 log4j.appender.D.layout = org.apache.log4j.PatternLayout 16 log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n 17 18 ######################## 19 20 # JDBC Appender 21 22 ####################### 23 24 25 ###info 26 log4j.rootLogger=INFO,stdout 27 log4j.logger.com=INFO,db 28 29 log4j.appender.db=com.neam.commons.MyJDBCAppender 30 31 log4j.appender.db=org.apache.log4j.jdbc.JDBCAppender 32 33 log4j.appender.db.BufferSize=1 34 35 log4j.appender.db.driver=oracle.jdbc.driver.OracleDriver 36 37 log4j.appender.db.URL=jdbc:oracle:thin:@127.0.0.1:1521:ORCL 38 39 log4j.appender.db.user=数据库名字40 41 log4j.appender.db.password=数据库密码42
###to_date(substr('%d',0,19),'yyyy-MM-dd hh24:mi:ss')这个是按系统当前时间插入到数据库 43 log4j.appender.db.sql=insert into tableExc (excID, class, createTime, logLevel, msg) values (exc_id_seq.nextval,'%C',to_date(substr('%d',0,19),'yyyy-MM-dd hh24:mi:ss'),'%p', '%m') 44 45 log4j.appender.db.layout=org.apache.log4j.PatternLayout