Log4j TimeBased 触发策略中 modulate = 'true' 表示什么

Sha*_*nga 5 java log4j log4j2

在下面的示例中,每天都会创建一个日志文件。考虑到这个例子,您能否提供一个场景来展示 modulate = 'true' 的用法,并将间隔设置为 1。

<Configuration status="warn" name="MyApp" packages="">
  <Appenders>
    <RollingFile name="RollingFile" fileName="logs/app.log"
                 filePattern="logs/app-%d{yyyy-MM-dd-HH}.log">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy interal = 1 modulate="true"/>
      </Policies>
    </RollingFile>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="RollingFile"/>
    </Root>
  </Loggers>
</Configuration> 
Run Code Online (Sandbox Code Playgroud)

rgo*_*ers 9

当 Log4j 初始化时,它将根据 %d 模式计算翻转间隔。当 modulate 为 false 时,将根据应用程序启动的时间进行翻转。因此,如果应用程序在下午 1:41 开始,并且最小时间间隔是小时,则下一次延期将在下午 2:41 发生。当 modulate 为 true 时,翻转将在“偶数”边界上发生 - 因此下一次翻转将发生在下午 3 点。

顺便说一句 - 示例中的 XML 无效。它应该是

<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
Run Code Online (Sandbox Code Playgroud)