简体   繁体   中英

What does modulate = 'true' signify in Log4j TimeBased Triggering Policy

In the below example, a log file is created every day. With this example in mind, could you please provide an scenario to show the usage of modulate = 'true' with the interval set as 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> 

When Log4j initializes it will calculate the rollover interval based on the %d pattern. When modulate is false then the rollover will happen based on the time the application started. So if the application started at 1:41 pm and the smallest time interval is the hour then the next rollover will occur at 2:41 pm. When modulate is true then the rollover will happen on "even" boundaries - so the next rollover would occur at 3pm.

BTW - the XML in the example is invalid. It should be

<TimeBasedTriggeringPolicy interval="1" modulate="true"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM