log4j 日志大小限制 分成30一个 不按日期分日志 按大小分成 按生产日期
首先说说生成按日期。不解释,大家都懂的,这种方法的缺点是很吃硬盘空间
log4j.rootLogger=INFO,logfile,stdout log4j.logger.java.sql=DEBUG,sqllog #log4j.additivity.java.sql=false #velocity print out log4j.logger.org.apache.velocity=ERROR,velocityfile log4j.additivity.org.apache.velocity=false log4j.logger.org.springframework.web.servlet.mvc.annotation=false #app print out log4j.logger.com.hundsun.network=DEBUG log4j.logger.com.hundsun.network.melody.common.profiler=DEBUG,profiler log4j.additivity.com.hundsun.network.melody.common.profiler=false #standout log appender # log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n #common log appender # log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender log4j.appender.logfile.File=/WEB-INF/log/app.log log4j.appender.logfile.append=true log4j.appender.logfile.encoding=GB18030 log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n #error log appender # log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender log4j.appender.errorfile.File=/WEB-INF/log/error.log log4j.appender.errorfile.Threshold=ERROR log4j.appender.errorfile.append=true log4j.appender.errorfile.encoding=GB18030 log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout log4j.appender.errorfile.layout.ConversionPattern=%d %p [%c] - %m%n #sql log appender # log4j.appender.sqllog=org.apache.log4j.DailyRollingFileAppender log4j.appender.sqllog.File=/WEB-INF/log/sql.log log4j.appender.sqllog.append=true log4j.appender.sqllog.encoding=GB18030 log4j.appender.sqllog.layout=org.apache.log4j.PatternLayout log4j.appender.sqllog.layout.ConversionPattern=%d %p [%c] - %m%n #velocity log appender # log4j.appender.velocityfile=org.apache.log4j.DailyRollingFileAppender log4j.appender.velocityfile.File=/WEB-INF/log/velocity.log log4j.appender.velocityfile.append=true log4j.appender.velocityfile.encoding=GB18030 log4j.appender.velocityfile.layout=org.apache.log4j.PatternLayout log4j.appender.velocityfile.layout.ConversionPattern=%d %p [%c] - %m%n #profile appender # log4j.appender.profiler=org.apache.log4j.DailyRollingFileAppender log4j.appender.profiler.File=/WEB-INF/log/profler.log log4j.appender.profiler.append=true log4j.appender.profiler.encoding=GB18030 log4j.appender.profiler.layout=org.apache.log4j.PatternLayout log4j.appender.profiler.layout.ConversionPattern=%d %p [%c] - %m%n
于是我们来解决一下这个问题。把日志的大小限在10240K,一共仅仅许生成30个。循环覆盖
log4j.rootLogger=INFO,logfile,stdout,errorfile log4j.logger.java.sql=@log.level@,sqllog log4j.additivity.java.sql=false #velocity print out log4j.logger.org.apache.velocity=ERROR,velocityfile log4j.additivity.org.apache.velocity=false #app print out log4j.logger.com.hundsun.network=DEBUG log4j.logger.com.hundsun.network.melody.common.profiler=@log.level@,profiler log4j.additivity.com.hundsun.network.melody.common.profiler=false #standout log appender # log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n #common log appender # log4j.appender.logfile=org.apache.log4j.RollingFileAppender log4j.appender.logfile.File=/WEB-INF/log/app.log log4j.appender.logfile.append=true log4j.appender.logfile.encoding=GB18030 log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.logfile.MaxFileSize=10240KB log4j.appender.logfile.MaxBackupIndex=30 #error log appender # log4j.appender.errorfile=org.apache.log4j.RollingFileAppender log4j.appender.errorfile.File=/WEB-INF/log/error.log log4j.appender.errorfile.Threshold=ERROR log4j.appender.errorfile.append=true log4j.appender.errorfile.encoding=GB18030 log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout log4j.appender.errorfile.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.errorfile.MaxFileSize=10240KB log4j.appender.errorfile.MaxBackupIndex=30 #sql log appender # log4j.appender.sqllog=org.apache.log4j.RollingFileAppender log4j.appender.sqllog.File=/WEB-INF/log/sql.log log4j.appender.sqllog.append=true log4j.appender.sqllog.encoding=GB18030 log4j.appender.sqllog.layout=org.apache.log4j.PatternLayout log4j.appender.sqllog.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.sqllog.MaxFileSize=10240KB log4j.appender.sqllog.MaxBackupIndex=30 #velocity log appender # log4j.appender.velocityfile=org.apache.log4j.RollingFileAppender log4j.appender.velocityfile.File=/WEB-INF/log/velocity.log log4j.appender.velocityfile.append=true log4j.appender.velocityfile.encoding=GB18030 log4j.appender.velocityfile.layout=org.apache.log4j.PatternLayout log4j.appender.velocityfile.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.velocityfile.MaxFileSize=10240KB log4j.appender.velocityfile.MaxBackupIndex=30 #profile appender # log4j.appender.profiler=org.apache.log4j.RollingFileAppender log4j.appender.profiler.File=/WEB-INF/log/profler.log log4j.appender.profiler.append=true log4j.appender.profiler.encoding=GB18030 log4j.appender.profiler.layout=org.apache.log4j.PatternLayout log4j.appender.profiler.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.profiler.MaxFileSize=10240KB log4j.appender.profiler.MaxBackupIndex=30
版权声明:本文博客原创文章。博客,未经同意,不得转载。