很多屌丝都觉得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:logslog.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:logslog_rolling.log
log4j.appenile.rolling_file.Append = true www.jb51.net
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:logslog_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