log4j.properties配置文件如下:
log4j.rootLogger=INFO,CONSOLE,FILE
#log控制台显示
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %d{yyyy-MM-dd HH:mm:ss S} - %m | %l%n
#log写入文件
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=F:/log/info.log
#log4j.appender.FILE.File=E:\\mywork\\CFM_xfire\\src\\run_
log4j.appender.file.DatePattern=yyyy_MM_dd'.log'
#log4j.appender.FILE.MaxBackupIndex=20
#log4j.appender.FILE.MaxFileSize=20MB
log4j.appender.FILE.Append=true
#log4j.appender.FILE.BufferSize=1k
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.BufferedIO=false
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=/n/n[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
//log写入数据库配置
log4j.appender.DATABASE=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.DATABASE.URL=jdbc:oracle:thin:@192.168.0.1:1521:siemen
log4j.appender.DATABASE.driver= oracle.jdbc.driver.OracleDriver
log4j.appender.DATABASE.user=
system
log4j.appender.DATABASE.password=css12345
log4j.appender.DATABASE.sql=INSERT INTO LOG4J (Message) VALUES ([framework] %d
- %c -%-4r [%t] %-5p %c %x - %m%n)
log4j.appender.DATABASE.layout=org.apache.log4j.PatternLayout
log4j.appender.DATABASE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t]
%-5p %c %x - %m%n
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=SampleMessages.log4j
log4j.appender.A1.DatePattern=yyyyMMdd-HH.log4j
log4j.appender.A1.layout=org.apache.log4j.xml.
XMLLayout