I am an Elasticsearch user and I have to use a log4j2.properties file. Unfortunately i can't get it to delete logs as I would like.
I want some log files (corresponding to a pattern) rotated every day. I also want the rotated log files to be deleted if it matches one of my 2 conditions:
- if they are more than 3 months old
- if the total size of these files exceeds 200 mega.
I try to use the PathCondition "ifany", described in this piece of log4j2 documentation: https://logging.apache.org/log4j/2.x/manual/appenders.html
Here is my log4j2.properties file:
status = error
# log action execution errors for easier debugging
logger.action.name = org.elasticsearch.action
logger.action.level = debug
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n
appender.rolling.type = RollingFile
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs}.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n
appender.rolling.filePattern = ${sys:es.logs}-%d{yyyy-MM-dd}.log
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.basepath = /var/log/elasticsearch
appender.rolling.strategy.action.condition.type = IfFileName
appender.rolling.strategy.action.condition.glob = mylog-*.log
appender.rolling.strategy.action.PathConditions.type = IfAny
appender.rolling.strategy.action.PathConditions.nestedConditions.type = IfLastModified
appender.rolling.strategy.action.PathConditions.nestedConditions.age = 90D
appender.rolling.strategy.action.PathConditions.nestedConditions.type = IfAccumulatedFileSize
appender.rolling.strategy.action.PathConditions.nestedConditions.exceeds = 200M
Currently, when I restart log4j2, I get the error message:
main ERROR IfAccumulatedFileSize contains an invalid element or attribute "age"
I would really appreciate any help on this subject. Thanks for your attention!