log4j2 删除操作中的 IfLastModified 条件未正确解释年龄持续时间

log4j2 IfLastModified condition in a Delete action is not interpreting age duration correctly

我似乎无法在我的 log4j Delete 操作中获得 IfLastModified 条件来正确解释按月设置的年龄。它一直使用它作为分钟。

我的 log4j XML 配置文件中有这个删除操作。

<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"

然而,这并没有任何效果。

Log4j2 Duration 对象不支持 Duration 中的月份格式。这一定是这种行为的原因。它记录在 API 文档 -

https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/rolling/action/Duration.html

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.