ESC*_*mas 3 properties conditional-statements log4j2
我是Elasticsearch用户,必须使用log4j2.properties文件。不幸的是,我无法按照自己的意愿删除日志。
我希望每天轮换一些日志文件(对应于某种模式)。我还希望如果旋转的日志文件符合我的2个条件之一,则将其删除:
我尝试使用该log4j2文档中介绍的PathCondition“ ifany”:https ://logging.apache.org/log4j/2.x/manual/appenders.html
这是我的log4j2.properties文件:
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
Run Code Online (Sandbox Code Playgroud)
当前,当我重新启动log4j2时,收到错误消息:
主要错误IfAccumulatedFileSize包含无效的元素或属性“ age”
我真的很感谢在这个问题上的任何帮助。感谢您的关注!
尝试DeleteAction
按照以下方式更改您的配置-
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.basepath = /var/log/elasticsearch
appender.rolling.strategy.action.maxDepth = 1
appender.rolling.strategy.action.condition.type = IfFileName
appender.rolling.strategy.action.condition.glob = mylog-*.log
appender.rolling.strategy.action.ifAny.type = IfAny
appender.rolling.strategy.action.ifAny.ifLastModified.type = IfLastModified
appender.rolling.strategy.action.ifAny.ifLastModified.age = 90d
appender.rolling.strategy.action.ifAny.ifAccumulatedFileSize.type = IfAccumulatedFileSize
appender.rolling.strategy.action.ifAny.ifAccumulatedFileSize.exceeds = 200MB
Run Code Online (Sandbox Code Playgroud)
您还可以参考log4j2
文档来配置多个条件。Log4j2
文档描述了XML配置。但是,通过参考这些示例,您也可以考虑和猜测属性配置。
归档时间: |
|
查看次数: |
1099 次 |
最近记录: |