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

huangapple go评论88阅读模式
英文:

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.

&lt;DefaultRolloverStrategy&gt;
   &lt;Delete basePath=&quot;${logging.dir}&quot; maxDepth=&quot;1&quot;&gt;
      &lt;IfFileName glob=&quot;framework-${hostName}-*.log&quot; /&gt;
      &lt;IfLastModified age=&quot;2m&quot; /&gt;
   &lt;/Delete&gt;
&lt;/DefaultRolloverStrategy&gt;

Unfortunately, it keeps using the age as minutes as seen from the logs:

createDeleteAction(basePath=&quot;./build/logs&quot;, followLinks=&quot;false&quot;, maxDepth=&quot;1&quot;, testMode=&quot;false&quot;, 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.

&lt;IfLastModified age=&quot;P2m&quot; /&gt;
...
&lt;IfLastModified age=&quot;P2M&quot; /&gt;

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=&quot;${logging.dir}/framework-${hostName}-%d{yyyy-MM-dd-HH-mm}.log&quot;

However, that did not have any effect.

答案1

得分: 2

Log4j2的Duration对象不支持在Duration中使用月份格式。这可能是这种行为的原因。在API文档中有记录:

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

这是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 -

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.

huangapple
  • 本文由 发表于 2020年9月29日 02:53:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/64108019.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定