log4j:WARN No such property [rollingPolicy] in org.apache.log4j.RollingFileAppender
Asked Answered
N

2

5

I am using log4j-1.2.16.jar and apache-log4j-extras-1.2.17.jar.

I want to enable rolling files with date appended to the filename. But showing this errot and files are not rotating as expected.

My log4j.properties file looks like this.

zookeeper.root.logger=DEBUG, ROLLINGFILE
zookeeper.console.threshold=DEBUG
zookeeper.log.dir=/path/to/logs
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=DEBUG
zookeeper.tracelog.dir=.
zookeeper.tracelog.file=zookeeper_trace.log
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
log4j.appender.ROLLINGFILE.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.ROLLINGFILE.rollingPolicy.fileNamePattern=${zookeeper.log.dir}/app%d{yyyy-MM-dd}.log
log4j.appender.ROLLINGFILE.MaxFileSize=20KB
log4j.appender.ROLLINGFILE.MaxBackupIndex=100000
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
Noun answered 20/2, 2017 at 5:48 Comment(4)
This may only be available from 1.2.17: https://mcmap.net/q/366773/-configuring-rollingfileappender-in-log4j And the versions of these two jar files should be aligned.Hilltop
@Hilltop Same issue exists even if I use log4j-1.2.17.jar and apache-log4j-extras-1.2.17.jar.Noun
Try DailyRollingFileAppender instead: https://mcmap.net/q/1988623/-log4j-warn-unrecognized-element-rollingpolicyHilltop
@Thil DailyRollingFileAppender does not rotate files by size right?Noun
N
10

Managed to fix it. The problem was with org.apache.log4j.RollingFileAppender . And it worked once I change it toorg.apache.log4j.rolling.RollingFileAppender

zookeeper.root.logger=DEBUG, ROLLINGFILE
zookeeper.console.threshold=DEBUG
zookeeper.log.dir=/path/to/logs
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=DEBUG
zookeeper.tracelog.dir=.
zookeeper.tracelog.file=zookeeper_trace.log
log4j.appender.ROLLINGFILE=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
log4j.appender.ROLLINGFILE.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.ROLLINGFILE.rollingPolicy.fileNamePattern=${zookeeper.log.dir}/app%d{yyyy-MM-dd}.log
log4j.appender.ROLLINGFILE.MaxFileSize=20KB
log4j.appender.ROLLINGFILE.MaxBackupIndex=100000
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
Noun answered 20/2, 2017 at 9:16 Comment(1)
Looking at the code of org.apache.log4j.rolling.RollingFileAppender, this solution wouldn't have worked. While the class have the rollingPolicy & rollingPolicy.fileNamePattern fields, it doesn't have MaxFileSize & MaxBackupIndex files. Did you check the error log? It is opposite in org.apache.log4j.RollingFileAppender class. It just doesn't come in two flavors.Praline
P
1

Looking at the code of org.apache.log4j.rolling.RollingFileAppender which is from a separate apache-log4j-extras package, this solution wouldn't have worked. While the class have the rollingPolicy & rollingPolicy.fileNamePattern fields, it doesn't have maxFileSize & maxBackupIndex fields. Did you check the error log?

It is opposite in org.apache.log4j.RollingFileAppender class. It has the MaxFileSize & maxBackupIndex fields but not rollingPolicy & rollingPolicy.fileNamePattern fields. It just doesn't come in two flavors.

Praline answered 3/6, 2019 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.