简体   繁体   中英

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

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>  

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