admin管理员组文章数量:1122832
I am using %d{UNIX} with apache log4j which is not working gradle file:
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.24.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.24.1'
log4j2.xml
<RollingFile name="ROLLING" fileName="logs/app.log" filePattern="logs/app-%d{UNIX}.log.gz" ignoreExceptions="false">
<PatternLayout>
<Pattern>%m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="5" modulate="true"/>
<SizeBasedTriggeringPolicy size="20 KB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
Error :
ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender
I am refering the doc: Pattern Layout Log4j
I am using %d{UNIX} with apache log4j which is not working gradle file:
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.24.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.24.1'
log4j2.xml
<RollingFile name="ROLLING" fileName="logs/app.log" filePattern="logs/app-%d{UNIX}.log.gz" ignoreExceptions="false">
<PatternLayout>
<Pattern>%m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="5" modulate="true"/>
<SizeBasedTriggeringPolicy size="20 KB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
Error :
ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender
I am refering the doc: Pattern Layout Log4j
Share Improve this question edited Nov 25, 2024 at 9:09 RCS asked Nov 22, 2024 at 16:18 RCSRCS 1,43212 silver badges31 bronze badges 1- Can you add the entire error message (with stacktrace) to the question? – Piotr P. Karwasz Commented Nov 22, 2024 at 22:38
1 Answer
Reset to default 0The TimeBasedTriggeringPolicy
determines the rollover interval based on the %d{...}
pattern (see documentation). For example if your pattern is %d{dd-HH-mm}
then the rollover interval will be minutes.
However, the Log4j-specific UNIX
specifier is not supported. If it were supported, it would probably use a rollover interval measured in seconds. Are you trying to rotate your files every 5 seconds?
Edit: I noticed another problem in your configuration: you don't have a %i
pattern, which is required so that size-based rollovers don't overwrite old files.
There are different requirements on the file pattern, depending on what policies you use:
- If you use only a size-based policy, you need
%d
,%i
or both. The date pattern will be filled with the current rollover timestamp. - If you use only a time-based policy, you need
%d
with a supported pattern to determine the rollover period. The pattern will be replaced with the timestamp of the previous rollover. - If you use both, you need both the
%d
and%i
patterns. Each triggering policy is then responsible for its pattern: size-based rollovers will increment%i
, time-based rollovers will increment%d
.
本文标签: log4j2Unix time is not working with log4j to perform file rolloverStack Overflow
版权声明:本文标题:log4j2 - Unix time is not working with log4j to perform file rollover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302406a1931520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论