很多絲都覺得log4j不好用,因為它不輸出到IDE的控制台,哈哈,其實都是配置惹的禍,下面看我怎麼一步步配置到控制台的,log4j的輸出級別和輸出模式相信絲們都知道的,這裡不多說了,直接看程式碼註解:
# All,TRACE,DEBUG,INFO,WARN,ERROR,FITAL,OFF
#全域專案日誌配置
log4j.rootLogger=ERROR
#指定的套件下所有的日誌(只輸出項目com套件下的日誌)
log4j.logger.com=DEBUG,yin,dailly_rolling_file
#指定輸出等級不受全域管理
log4j.additivity.com=false
# 輸出到控制台
log4j.appender.yin = org.apache.log4j.ConsoleAppender
log4j.appender.yin.layout = org.apache.log4j.PatternLayout
log4j.appender.yin.layout.ConversionPattern = %n%d [%p] [%m] [%c] %M()[%L] %n
# 輸出到文件
log4j.appender.file = org.apache.log4j.FileAppender
log4j.appender.file.File = C/://logs//log.log
log4j.appenile.file.Append = true
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %-d{yyyy-MM-dd HH/:mm/:ss,SSS} [%c]-[%p] %m%n
#輸出到大小滾動檔(100表示備份檔個數)
log4j.appender.rolling_file = org.apache.log4j.RollingFileAppender
log4j.appender.rolling_file.Threshold = ERROR
log4j.appender.rolling_file.File = C/://logs//log_rolling.log
log4j.appenile.rolling_file.Append = true www.VeVB.COm
log4j.appenile.rolling_file.MaxFileSize = 10KB
log4j.appenile.rolling_file.MaxBackupIndex = 100
log4j.appender.rolling_file.layout = org.apache.log4j.PatternLayout
log4j.appender.rolling_file.layout.ConversionPattern = %-d{yyyy-MM-dd HH/:mm/:ss,SSS} [%c]-[%p] %m%n
# 輸出到按日期滾動文件
log4j.appender.dailly_rolling_file = org.apache.log4j.DailyRollingFileAppender
log4j.appender.dailly_rolling_file.File = C/://logs//log_daily_rolling.log
log4j.appender.dailly_rolling_file.DatePattern = .yyyy-MM-dd
log4j.appender.dailly_rolling_file.layout=org.apache.log4j.PatternLayout
log4j.appender.dailly_rolling_file.layout.ConversionPattern=%-d{yyyy-MM-dd HH/:mm/:ss,SSS} [%c]-[%p] %m%n