我想创建一个简单的TimeBasedTriggeringPolicy
,每5分钟创建一个新的日志文件。但是它没有记录任何东西。我不知道我做错了什么。这里是详细信息,谢谢!
我的log4j依赖项:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
log4j.rootLogger=INFO,rolling
log4j.appender.rolling.type=RollingFile
log4j.appender.rolling.name=fileAppender
log4j.appender.rolling.fileName=${spark.yarn.app.container.log.dir}/spark-${date:yyyyMMdd_HH-mm}.log
log4j.appender.rolling.filePattern=${spark.yarn.app.container.log.dir}/spark-%d{yyyyMMdd_HH-mm}-%i.log
log4j.appender.rolling.layout.type=PatternLayout
log4j.appender.rolling.layout.pattern=%d %p %t %c - %m%n
log4j.appender.rolling.policies.type=Policies
log4j.appender.rolling.policies.time.type=TimeBasedTriggeringPolicy
log4j.appender.rolling.policies.time.interval=5
log4j.appender.rolling.policies.time.modulate=true
log4j.rootLogger.level=info
log4j.rootLogger.appenderRef.rolling.ref=fileLogger
错误日志:
log4j:ERROR Could not find value for key log4j.appender.rolling
log4j:ERROR Could not instantiate appender named "rolling".
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/mnt1/yarn/usercache/hadoop/filecache/45/__spark_libs__6130489434181934811.zip/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/lib/hadoop/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
- 最终工作结果(每分钟创建日志,每月轮换):**
log4j.rootLogger=INFO, loggerId
log4j.appender.loggerId=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.loggerId.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.loggerId.rollingPolicy.ActiveFileName=${spark.yarn.app.container.log.dir}/spark.log
log4j.appender.loggerId.rollingPolicy.FileNamePattern=${spark.yarn.app.container.log.dir}/spark_%d{dd-HHmm}.log.gz
log4j.appender.loggerId.layout=org.apache.log4j.PatternLayout
log4j.appender.loggerId.layout.ConversionPattern=%d %p %t %c - %m%n
log4j.appender.loggerId.encoding=UTF-8
2条答案
按热度按时间iswrvxsc1#
您的配置中有几个错误(使用
-Dlog4j.debug=true
运行以捕获所有错误):log4j.
的属性,请删除前缀,spark.yarn.app.container.log.dir
属性。如果您要使用Java系统属性,请使用${sys:spark.yarn.app.container.log.dir}
。rootLogger = INFO, rolling
,两个定义都不使用您给附加器的名称:* *
fileAppender
**.<SizeBasedRollingPolicy>
,但您的模式包含%i
。如果删除-%i
,则fileName
和filePattern
相同:您可能希望使用直接滚动策略并省略fileName
。zvms9eto2#
这将每分钟创建一个日志,我们不能以5分钟为增量,除非我们使用xml或自定义。
它每月旋转一次,我去掉了
yyyyMM
,这样它就可以每月旋转一次,去掉dd
,它就会每天旋转一次: