java - Log4j RollingFileAppender every minute -
i'm testing log4j rollingfileappender log4j 2.6.2.
i want rotate logs every minute , have log4j2.xml similar 1 example of here https://logging.apache.org/log4j/2.x/manual/appenders.html#rollingfileappender. log4j2.xml
<?xml version="1.0" encoding="utf-8"?> <configuration status="warn" name="testlog4j2" packages=""> <properties> <property name="basedir">c:/tmp/testlog4</property> </properties> <appenders> <rollingfile name="rollingfile" filename="${basedir}/app.log" filepattern="${basedir}/$${date:yyyy-mm}/app-%d{yyyy-mm-dd-hh-mm}.log.gz"> <patternlayout pattern="%d %p %c{1.} [%t] %m%n" /> <crontriggeringpolicy schedule="0 0/1 * * * ?"/> <defaultrolloverstrategy> <delete basepath="${basedir}" maxdepth="2"> <iffilename glob="*/app-*.log.gz" /> <iflastmodified age="60d" /> </delete> </defaultrolloverstrategy> </rollingfile> </appenders> <loggers> <root level="all"> <appenderref ref="rollingfile"/> </root> </loggers> </configuration>
and app write log every second.
package testlog4j2; import org.apache.logging.log4j.logmanager; import org.apache.logging.log4j.logger; public class testlog4j { private final static logger logger = logmanager.getlogger(testlog4j.class); public static void main(string[] args) { try { (int i=1; i<=240; i++) { logger.info("hello"); thread.sleep(1*1000); } } catch (exception e) { //e.printstacktrace(); logger.error("excepcion general", e); } } }
what happens is:
once system rotates log @ first minute appears continuously errors this
2016-07-28 15:10:02,015 log4j2-log4j2scheduled-1 error unable move file c:\tmp\testlog4\2016-07\app-2016-07-28-15-10.log.gz c:\tmp\testlog4\2016-07\app-2016-07-28-15-10.log.gz: java.nio.file.nosuchfileexception c:\tmp\testlog4\2016-07\app-2016-07-28-15-10.log.gz -> c:\tmp\testlog4\2016-07\app-2016-07-28-15-10.log.gz
there isn't gz every minute
- the result gz don't have log 60 lines. instead have 1, 2 or 3 lines of log.
- the main log c:\tmp\testlog4\app.log has no content
what i'm doing wrong?
thanks
you may have found bug. please raise bug report on jira issue tracker details describe here.
Comments
Post a Comment