简体   繁体   中英

Log4j2 DefaultRolloverStrategy Configuration does not delete old logs

I'm using log4j2 for my app logs, I'm using XML and the configuration below is for the logs, it moves the logs everyday to the old folder, but it's not removing then

<RollingFile name="fileappenderMAIL" fileName="/home/server/logs/EMAIL/SM_Mail.log"
                         filePattern="/home/server/logs/old/$${date:yyyy-MM}/EMAIL/SM_Mail-%d{dd-MM-yyyy}-%i.log.gz" immediateFlush="false">
                <PatternLayout pattern="%d %p %C{1.} [%t] %m%n" />
                <Policies>
                    <TimeBasedTriggeringPolicy />
                    <SizeBasedTriggeringPolicy size="10 MB"/>
                </Policies>
                <DefaultRolloverStrategy >
                    <Delete basePath="/home/server/logs/old/" maxDepth="3">
                        <IfFileName glob="*/EMAIL/SM_Mail-??-??-????-*.log">
                            <IfAny>
                                <IfAccumulatedFileSize exceeds="10 KB" />
                                <IfAccumulatedFileCount exceeds="30" />
                            </IfAny>
                        </IfFileName>
                    </Delete>
                </DefaultRolloverStrategy>
            </RollingFile>

It's supposed to be removing the old elements, have anyone any idea what I'm missing or doing wrong?

Dunno if it's useful but I'm deploying in Wildfly 10 with Java 7 and Log4j version 2.8.1, also I'm using com.lmax.disruptor so as to use AsyncLoggers

Thanks

You can investigate what is happening by changing your configuration file to start with <Configuration status="trace"> . This will print internal Log4j2 logging to the console.

During rollover this will give you information on which files and directories the Delete action considered and why it decided not to do anything.


Thanks for the comment, I see what the problem is now. The glob pattern matches files ending in .log . The rollover pattern results in files ending in .log.gz . (Same as the file you mentioned in the comment.) The glob won't match so the file is not deleted.

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