1
votes

I'm using Apache Flink v1.2. I wanted to switch to a rolling file appender to avoid huge log files containing data for several days. However it doesn't seem to work. I adapted the log4j Configuration (log4j.properties) as follows:

log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.file.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.file.DatePattern='.' yyyy-MM-dd-a'.log'
log4j.appender.file.MaxBackupIndex = 15
log4j.appender.file.append=false
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n

First it complains it cannot find org.apache.log4j.rolling.RollingFileAppender. So I switch it to org.apache.log4j.RollingFileAppender and then it says RollingPolicy and DatePattern are not valid attributes for the RollingFileAppender.

Did anyone else encounter same issues / can you suggest what's wrong with this configuration?

1

1 Answers

1
votes

In order to use the RollingFileAppender you first have to add the apache-log4j-extras-1.2.17.jar to your classpath (e.g. adding it to Flink's lib folder).

Next you have to configure it and specify a FileNamePattern before specifying the RollingPolicy. With the following log4j.properties file I can use the RollingFileAppender.

log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.file.RollingPolicy.FileNamePattern=logs/log.%d{yyyyMMdd-HHmm}.log
log4j.appender.file.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.file.append=false
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n