英文:
log4j2 IfLastModified condition in a Delete action is not interpreting age duration correctly
问题
我似乎无法正确使我的 log4j 的 Delete 操作中的 IfLastModified 条件正确解释以月为单位设置的年龄。它一直将其视为分钟。
我在我的 log4j XML 配置文件中有以下的 Delete 操作。
<DefaultRolloverStrategy>
<Delete basePath="${logging.dir}" maxDepth="1">
<IfFileName glob="framework-${hostName}-*.log" />
<IfLastModified age="2m" />
</Delete>
</DefaultRolloverStrategy>
不幸的是,它一直将年龄视为分钟,从日志中可以看到:
createDeleteAction(basePath="./build/logs", followLinks="false", maxDepth="1", testMode="false", PathSorter=null, ={IfFileName(glob:framework-SY4-9CMY2W2-*.log), IfLastModified(age=PT2M)}, ScriptCondition=null, Configuration...
根据持续时间规范
https://en.wikipedia.org/wiki/ISO_8601#Durations
"为了消除歧义,"P1M" 是一个一个月的持续时间,而 "PT1M" 是一个一分钟的持续时间(注意在时间值之前有时间指示符 T)"
我尝试使用不同的持续时间格式来指定年龄,但结果相同。
<IfLastModified age="P2m" />
...
<IfLastModified age="P2M" />
我知道我可以指定 60D,但我想知道为什么不能使用月份持续时间。
我使用的是 log4j 2.12.1
此外,我怀疑可能是因为 filePattern 是以分钟为单位的。
filePattern="${logging.dir}/framework-${hostName}-%d{yyyy-MM-dd-HH-mm}.log"
然而,这没有任何效果。
英文:
I can't seem to get the IfLastModified condition in my log4j Delete action to properly interpret an age set in months. It keeps using it as minutes.
I have this Delete action in my log4j XML configuration file.
<DefaultRolloverStrategy>
<Delete basePath="${logging.dir}" maxDepth="1">
<IfFileName glob="framework-${hostName}-*.log" />
<IfLastModified age="2m" />
</Delete>
</DefaultRolloverStrategy>
Unfortunately, it keeps using the age as minutes as seen from the logs:
createDeleteAction(basePath="./build/logs", followLinks="false", maxDepth="1", testMode="false", PathSorter=null, ={IfFileName(glob:framework-SY4-9CMY2W2-*.log), IfLastModified(age=PT2M)}, ScriptCondition=null, Configuration...
According to the Duration specification
https://en.wikipedia.org/wiki/ISO_8601#Durations
"To resolve ambiguity, "P1M" is a one-month duration and "PT1M" is a one-minute duration (note the time designator, T, that precedes the time value)"
I tried specifying the age using different Duration formats but the same result.
<IfLastModified age="P2m" />
...
<IfLastModified age="P2M" />
I know I can specify 60D but I'm wondering why I can't use months duration.
I am using log4j 2.12.1
Furthermore, I suspected it could be because the filePattern was in minutes.
filePattern="${logging.dir}/framework-${hostName}-%d{yyyy-MM-dd-HH-mm}.log"
However, that did not have any effect.
答案1
得分: 2
Log4j2的Duration对象不支持在Duration中使用月份格式。这可能是这种行为的原因。在API文档中有记录:
这是ISO-8601持续时间标准的简化实现。支持的格式是PnDTnHnMnS,其中'P'和'T'是可选的。天被视为确切的24小时。
与java.time.Duration类类似,此类不支持格式中的年或月部分。此实现不支持小数或负值。
英文:
Log4j2 Duration object does not support month format in Duration. That must be the reason for this behaviour. It is documented here in API Documentation -
> Simplified implementation of the ISO-8601 Durations standard. The supported format is PnDTnHnMnS, with 'P' and 'T' optional. Days are considered to be exactly 24 hours.
>
> Similarly to the java.time.Duration class, this class does not support
> year or month sections in the format. This implementation does not
> support fractions or negative values.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论