File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -224,4 +224,15 @@ void testRolloverOfDeletedFile() throws IOException {
224224 }
225225 assertEquals (testContent , new String (Files .readAllBytes (file .toPath ()), StandardCharsets .US_ASCII ));
226226 }
227+
228+ @ Test
229+ @ Issue ("https://github.com/apache/logging-log4j2/issues/3068" )
230+ void testInitialTimeRounded () {
231+ assertEquals (1755031147000L , RollingFileManager .roundMillis (1755031147000L ));
232+ assertEquals (1755031147000L , RollingFileManager .roundMillis (1755031147123L ));
233+ assertEquals (1755031147000L , RollingFileManager .roundMillis (1755031147499L ));
234+ assertEquals (1755031148000L , RollingFileManager .roundMillis (1755031147500L ));
235+ assertEquals (1755031148000L , RollingFileManager .roundMillis (1755031147999L ));
236+ assertEquals (1755031148000L , RollingFileManager .roundMillis (1755031148000L ));
237+ }
227238}
Original file line number Diff line number Diff line change @@ -918,15 +918,24 @@ private static long initialFileTime(final File file) {
918918 final FileTime fileTime = attrs .creationTime ();
919919 if (fileTime .compareTo (EPOCH ) > 0 ) {
920920 LOGGER .debug ("Returning file creation time for {}" , file .getAbsolutePath ());
921- return fileTime .toMillis ();
921+
922+ return roundMillis (fileTime .toMillis ());
922923 }
923- LOGGER .info ("Unable to obtain file creation time for " + file .getAbsolutePath ());
924+ LOGGER .info ("Unable to obtain file creation time for {}" , file .getAbsolutePath ());
924925 } catch (final Exception ex ) {
925- LOGGER .info ("Unable to calculate file creation time for " + file . getAbsolutePath () + ": "
926- + ex .getMessage ());
926+ LOGGER .info (
927+ "Unable to calculate file creation time for {}: {}" , file . getAbsolutePath (), ex .getMessage ());
927928 }
928929 }
929- return file .lastModified ();
930+
931+ return roundMillis (file .lastModified ());
932+ }
933+
934+ /**
935+ * @see <a href="https://github.com/apache/logging-log4j2/issues/3068">Issue #3068</a>
936+ */
937+ static long roundMillis (long millis ) {
938+ return Math .round (millis / 1000d ) * 1000 ;
930939 }
931940
932941 private static class EmptyQueue extends ArrayBlockingQueue <Runnable > {
You can’t perform that action at this time.
0 commit comments