This commit is contained in:
Greg Wilkins 2017-04-27 10:57:37 +02:00
parent 8af0d153e0
commit 118652e985
1 changed files with 11 additions and 8 deletions

View File

@ -175,9 +175,12 @@ public class RolloverFileOutputStream extends FilterOutputStream
if (__rollover==null)
__rollover=new Timer(RolloverFileOutputStream.class.getName(),true);
midnight = toMidnight(ZonedDateTime.now(), zone.toZoneId());
ZonedDateTime now = ZonedDateTime.now(zone.toZoneId());
midnight = toMidnight(now, zone.toZoneId());
while (midnight.isBefore(now))
midnight = nextMidnight(midnight);
scheduleNextRollover();
scheduleNextRollover(now);
}
}
@ -205,11 +208,11 @@ public class RolloverFileOutputStream extends FilterOutputStream
return dateTime.toLocalDate().plus(1, ChronoUnit.DAYS).atStartOfDay(dateTime.getZone());
}
private void scheduleNextRollover()
private void scheduleNextRollover(ZonedDateTime now)
{
_rollTask = new RollTask();
midnight = nextMidnight(midnight);
__rollover.schedule(_rollTask,midnight.toInstant().toEpochMilli() - System.currentTimeMillis());
__rollover.schedule(_rollTask,midnight.toInstant().toEpochMilli() - now.toInstant().toEpochMilli());
}
/* ------------------------------------------------------------ */
@ -276,11 +279,10 @@ public class RolloverFileOutputStream extends FilterOutputStream
}
/* ------------------------------------------------------------ */
private void removeOldFiles()
private void removeOldFiles(ZonedDateTime now)
{
if (_retainDays>0)
{
ZonedDateTime now = ZonedDateTime.now(this.midnight.getZone());
now.minus(_retainDays, ChronoUnit.DAYS);
long expired = now.toInstant().toEpochMilli();
@ -354,9 +356,10 @@ public class RolloverFileOutputStream extends FilterOutputStream
{
try
{
ZonedDateTime now = ZonedDateTime.now(midnight.getZone());
RolloverFileOutputStream.this.setFile();
RolloverFileOutputStream.this.scheduleNextRollover();
RolloverFileOutputStream.this.removeOldFiles();
RolloverFileOutputStream.this.scheduleNextRollover(now);
RolloverFileOutputStream.this.removeOldFiles(now);
}
catch(Throwable t)
{