user10776719
user10776719

Reputation: 341

log4j2 CronTriggeringPolicy not recognized within RollingFile appender

Issue:

Based on the documentation (https://logging.apache.org/log4j/2.x/manual/appenders.html), I am trying to keep up to 10 5 GB files per day, for a max of 30 days. My appenders look like this:

<Appenders>
    <RollingFile 
        name="FILE" 
        fileName="${env:LOG_BASE}/my-app.log" 
        filePattern="${env:LOG_BASE}/my-app-%d{yyyy-MM-dd}-%i.log" 
        append="true">

        <PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
        <CronTriggeringPolicy schedule="0 0 0 * * ?" evaluateOnStartup="true" />

        <Policies>
            <SizeBasedTriggeringPolicy size="5000MB" />
        </Policies>  

        <DefaultRolloverStrategy max="10">
            <Delete basePath="${env:LOG_BASE}">
                <IfLastModified age="30d" />
            </Delete>
        </DefaultRolloverStrategy>
    </RollingFile>

    <Console 
        name="STDOUT" 
        target="SYSTEM_OUT" 
        follow="true">
        <PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
    </Console>
</Appenders>

Here is the exception:

ERROR appender RollingFile has no parameter that matches element CronTriggeringPolicy

What am I missing? I've seen the CronTriggeringPolicy in both the policies and as a child of the RollingFile level

Version: 2.8.2

Edit: I also should add, nothing changed when I pushed CronTriggeringPolicy into policies

Upvotes: 1

Views: 3155

Answers (1)

Isidro.rn
Isidro.rn

Reputation: 314

You have declared the CronTriggeringPolicy directly under the appender when you should have placed it into the Policies, like this:

<RollingFile 
    name="FILE" 
    fileName="${env:LOG_BASE}/my-app.log" 
    filePattern="${env:LOG_BASE}/my-app-%d{yyyy-MM-dd}-%i.log" 
    append="true">

    <PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
    
    <Policies>
        <CronTriggeringPolicy schedule="0 0 0 * * ?" evaluateOnStartup="true" />
        <SizeBasedTriggeringPolicy size="5000MB" />
    </Policies>  

Upvotes: 3

Related Questions