I understand that i can use a DailyRollingFileAppender to roll the log file every month, day, half-day, hour or minute. But how can i configure log4j to roll the log file ev
With logback, you can subclass the RollingFileAppender.
public class FifteenMinuteAppender extends RollingFileAppender
{
private static long start = System.currentTimeMillis(); // minutes
private int rollOverTimeInMinutes = 15;
@Override
public void rollover()
{
long currentTime = System.currentTimeMillis();
int maxIntervalSinceLastLoggingInMillis = rollOverTimeInMinutes * 60 * 1000;
if ((currentTime - start) >= maxIntervalSinceLastLoggingInMillis)
{
super.rollover();
start = System.currentTimeMillis();
}
}
}
Then use that appender as your appender with a rolling policy
yourfile.csv
yourfile-%d{yyyyMMdd-HHmm}.csv
%d{YYYYMMDD-HHmmSS-ZZ};${HOSTNAME};%thread;%msg%n
More details here