问题?多功能的log4j.properties配置详解如下
log4j.rootLogger=DEBUG,CONSOLE,DATABASE,FILE log4j.addivity.org.apache=true
# 应用于控制台
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=INFO log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.Encoding=GBK log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.conOut.layout.ConversionPattern=%d %-5p [%c] %m%n
# 用于数据库
log4j.appender.DATABASE=org.apache.log4j.jdbc.JDBCAppender log4j.appender.DATABASE.URL=jdbc:oracle:thin:@192.168.0.103:1521:ORCL log4j.appender.DATABASE.driver=oracle.jdbc.driver.OracleDriver log4j.appender.DATABASE.user=Nation log4j.appender.DATABASE.password=1 log4j.appender.CONSOLE.Threshold=WARN log4j.appender.DATABASE.sql=INSERT INTO LOG4J(stamp,thread, infolevel,class,messages) VALUES ('%d{yyyy-MM-dd HH:mm:ss}', '%t', <span style="font-family: 'Microsoft YaHei';font-size:18px;">'%p', '%l', '%m')</span>
# INSERT INTO LOG4J (Message) VALUES ('[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n')
# 写入数据库中的表LOG4J的Message字段中,内容%d(日期)%c: 日志信息所在地(类名)%p: 日志信息级别%m: 产生的日志具体信息 %n: 输出日
志信息换行
log4j.appender.DATABASE.layout=org.apache.log4j.PatternLayout log4j.appender.DATABASE.layout.ConversionPattern=%d %-5p [%c] %m%n
# 每天新建日志
#(警告的意思是DailyRollingFileAppender这个类不带属性maxBackupIndex,maxFileSize的,它是#按日期来保存日志的,所以不需要设置该2个属性,如果想要设置日志文件的大小,可以使用#RollingFileAppender这个类,平时开发中日志配置文件中需要注意设置。)
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender log4j.appender.A1.File=./logs/cebLog.txt log4j.appender.A1.Encoding=GBK log4j.appender.A1.Threshold=DEBUG log4j.appender.A1.DatePattern='.'yyyy-MM-dd log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L : %m%n
#应用于文件
#(警告的意思是DailyRollingFileAppender这个类不带属性maxBackupIndex,maxFileSize的,它是#按日期来保存日志的,所以不需要设置该2个属
性,如果想要设置日志文件的大小,可以使用#RollingFileAppender这个类,平时开发中日志配置文件中需要注意设置。)
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender log4j.appender.File.File=./logs/cebLog.txt log4j.appender.File.DatePattern='_'yyyy-MM-dd'.txt' #log4j.appender.File.MaxFileSize=100KB #log4j.appender.File.MaxBackupIndex=100 log4j.appender.File.layout=org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern=%d %t %-5p [%c] %m%n
# 应用于文件回滚(即文件到达MaxFileSize就会产生一个新的文件,MaxBackupIndex是指文件的最大数目)
log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender log4j.appender.ROLLING_FILE.Threshold=ERROR log4j.appender.ROLLING_FILE.File=rolling.log log4j.appender.ROLLING_FILE.Append=true log4j.appender.CONSOLE_FILE.Encoding=GBK log4j.appender.ROLLING_FILE.MaxFileSize=10KB log4j.appender.ROLLING_FILE.MaxBackupIndex=1 log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout log4j.appender.ROLLING_FILE.layout.ConversionPattern=%d %-5p [%c] %m%n
#自定义Appender
log4j.appender.im = net.cybercorlin.util.logger.appender.IMAppender log4j.appender.im.host = mail.cybercorlin.net log4j.appender.im.username = username log4j.appender.im.password = password log4j.appender.im.recipient = yyflyons@163.com log4j.appender.im.layout=org.apache.log4j.PatternLayout log4j.appender.im.layout.ConversionPattern =%d %-5p [%c] %m%n
#应用于socket
log4j.appender.SOCKET=org.apache.log4j.RollingFileAppender log4j.appender.SOCKET.RemoteHost=localhost log4j.appender.SOCKET.Port=5001 log4j.appender.SOCKET.LocationInfo=true # Set up for Log Facter 5 log4j.appender.SOCKET.layout=org.apache.log4j.PatternLayout log4j.appender.SOCET.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]%n%c[CATEGORY]%n%m<span style="font-family: 'Microsoft YaHei';font-size:18px;">[MESSAGE]%n%n</span>
# Log Factor 5 Appender
log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000
# 发送日志给邮件
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender log4j.appender.MAIL.Threshold=FATAL log4j.appender.MAIL.BufferSize=10 log4j.appender.MAIL.From=yyflyons@163.com log4j.appender.MAIL.SMTPHost=www.wusetu.com log4j.appender.MAIL.Subject=Log4J Message log4j.appender.MAIL.To=yyflyons@126.com log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout log4j.appender.MAIL.layout.ConversionPattern=%d %-5p [%c] %m%n