Apache Flink RollingFileAppender [英] Apache Flink RollingFileAppender

查看:37
本文介绍了Apache Flink RollingFileAppender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 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 然后它说 RollingPolicyDatePattern 不是 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).

接下来您必须配置它并在指定 RollingPolicy 之前指定一个 FileNamePattern.使用以下 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆