问题描述
我正在使用Apache Flink v1.2.我想切换到滚动文件追加程序,以避免几天之内包含数据的巨大日志文件.但是,它似乎不起作用.我修改了log4j配置( log4j.properties
),如下所示:
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
首先,它抱怨找不到 org.apache.log4j.rolling.RollingFileAppender
.所以我将其切换到 org.apache.log4j.RollingFileAppender
,然后说 RollingPolicy
和 DatePattern
对于 RollingFileAppender来说不是有效的属性
.
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?
推荐答案
要使用 RollingFileAppender
,您首先必须添加 apache-log4j-extras-1.2.17.jar
到您的类路径(例如,将其添加到Flink的 lib
文件夹中).
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).
接下来,您必须先配置它并指定 FileNamePattern
,然后再指定 RollingPolicy
.通过以下 log4j.properties
文件,我可以使用 RollingFileAppender
.
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
这篇关于Apache Flink RollingFileAppender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!