开发者

log4j:Appender to print the log Statements

Hello sir: When server is started ,the log files print the output statement..ho开发者_如何学Cw can i print the log files in my own file?


You can try using a properties file

log4j.rootLogger=INFO, ERRORFILE

#ERRORFILE - used to log error messages
log4j.appender.ERRORFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ERRORFILE.Threshold=ERROR
log4j.appender.ERRORFILE.File=errorLog.log
log4j.appender.ERRORFILE.MaxFileSize=200KB
log4j.appender.ERRORFILE.MaxBackupIndex=5
log4j.appender.ERRORFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ERRORFILE.layout.ConversionPattern=%d{DATE} %t - %m%n

In this example, I configured a properties file to log error messages to my own file, errorLog.log. Here's another sample.


Configure a log4j properties file with file appender. Something like this -

log4j.rootLogger=WARN, fileAppender
log4j.logger.myPackage=DEBUG, fileAppender
log4j.additivity.myPackage=false
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File= C://Myfile.log
log4j.appender.fileAppender.MaxFileSize=1024KB 
log4j.appender.fileAppender.MaxBackupIndex=5 
log4j.appender.fileAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜