滚动文件附加器属性

时间:2018-06-27 03:53:50

标签: java logging log4j

为什么即使设置了MaxFileSize,log4j滚动文件附加器仍继续将日志写入同一文件?

它仅在服务器重新启动时创建一个新的日志文件。为什么?

# Root logger option 
log4j.rootLogger=INFO, file, stdout 
# Direct log messages to a log file 
log4j.appender.file=org.apache.log4j.RollingFileAppender 
log4j.appender.file.File=file_path 
log4j.appender.file.MaxFileSize=500MB 
log4j.appender.file.MaxBackupIndex=10 
log4j.appender.file.layout=org.apache.log4j.PatternLayout 
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n # Direct log messages to stdout 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.Target=System.out 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

1 个答案:

答案 0 :(得分:0)

请检查下面的log4J配置。

enter image description here

# Root logger option
log4j.rootLogger=INFO, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Redirect log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#outputs to Tomcat home
log4j.appender.file.Append=false
log4j.appender.file.File=C:/LogFolder/myapp.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n