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 {
224
224
}
225
225
assertEquals (testContent , new String (Files .readAllBytes (file .toPath ()), StandardCharsets .US_ASCII ));
226
226
}
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
+ }
227
238
}
Original file line number Diff line number Diff line change @@ -918,15 +918,24 @@ private static long initialFileTime(final File file) {
918
918
final FileTime fileTime = attrs .creationTime ();
919
919
if (fileTime .compareTo (EPOCH ) > 0 ) {
920
920
LOGGER .debug ("Returning file creation time for {}" , file .getAbsolutePath ());
921
- return fileTime .toMillis ();
921
+
922
+ return roundMillis (fileTime .toMillis ());
922
923
}
923
- LOGGER .info ("Unable to obtain file creation time for " + file .getAbsolutePath ());
924
+ LOGGER .info ("Unable to obtain file creation time for {}" , file .getAbsolutePath ());
924
925
} 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 ());
927
928
}
928
929
}
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 ;
930
939
}
931
940
932
941
private static class EmptyQueue extends ArrayBlockingQueue <Runnable > {
You can’t perform that action at this time.
0 commit comments