javalog4jlog4j2

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>

Solution

  • When Log4j initializes it will calculate the rollover interval based on the %d pattern.

    BTW - the XML in the example is invalid. It says interal=1 (the letter v is missing and the quotes around 1 are missing)...

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

    ...but it SHOULD say interval="1" like so:

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