log4j 配置

1、首先ar包:log4j-1.2.15.jar,mail.jar,activation-1.1.jar

2、新建 log4j.properties,注意存放在src目录下面


3、配置

log4j.rootLogger=DEBUG,CONSOLE,FILE,MAIL
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=utf8
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n


#输出日志文件
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=/usr/local/log4j/file.log
log4j.appender.FILE.Append=false
log4j.appender.FILE.Encoding=utf8
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n

#\u5E94\u7528\u4E8Esocket
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[MESSAGE]%n%n
# Log Factor 5 Appender
log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender
log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000

## MAIL
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
log4j.appender.MAIL.Threshold=ERROR
log4j.appender.MAIL.BufferSize=1
log4j.appender.MAIL.SMTPHost=smtp.163.com
log4j.appender.MAIL.Subject=messageFromTomcatByYangxujia
log4j.appender.MAIL.From=***@163.com
log4j.appender.MAIL.To=***@qq.com
#注意,这块不能带@163.com
log4j.appender.MAIL.SMTPUsername=***
log4j.appender.MAIL.SMTPPassword=
log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.MAIL.layout.ConversionPattern=[ErrorMessage] %d - %c -%-4r [%t] %-5p %c %x - %m%n


你可能感兴趣的:(log4j)