diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTempCompressedFilePatternTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTempCompressedFilePatternTest.java index 4b343f09d1c..837f797bb07 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTempCompressedFilePatternTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTempCompressedFilePatternTest.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.core.appender.rolling; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import java.io.InputStream; import java.nio.charset.Charset; @@ -83,7 +84,7 @@ void testAppender(final LoggerContext context) throws Exception { AtomicInteger fileCount = new AtomicInteger(); AtomicInteger gzippedFileCount = new AtomicInteger(); try (final DirectoryStream files = Files.newDirectoryStream(logsDir)) { - assertThat(files).allSatisfy(file -> { + files.forEach(file -> assertDoesNotThrow(() -> { fileCount.incrementAndGet(); final boolean isGzipped = file.getFileName().toString().endsWith(".gz"); if (isGzipped) { @@ -97,7 +98,7 @@ void testAppender(final LoggerContext context) throws Exception { lines.forEach(messages::remove); } } - }); + })); } assertThat(messages).as("Lost messages").isEmpty(); assertThat(fileCount).as("Log file file count").hasValueGreaterThan(16); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java index e214eb8a107..fd40406b958 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java @@ -147,11 +147,14 @@ public DefaultRolloverStrategy build() { // The config object can be null only in tests final Configuration configuration = config != null ? config : new NullConfiguration(); final StrSubstitutor nonNullStrSubstitutor = configuration.getStrSubstitutor(); + final Map compressionOptions = compressionLevel != null + ? Map.of(CompressActionFactory.COMPRESSION_LEVEL, compressionLevel) + : Map.of(); return new DefaultRolloverStrategy( minIndex, maxIndex, useMax, - Map.of(CompressActionFactory.COMPRESSION_LEVEL, compressionLevel), + compressionOptions, nonNullStrSubstitutor, customActions, stopCustomActionsOnError, diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java index a79952e2fcf..8cc919025db 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java @@ -96,9 +96,12 @@ public DirectWriteRolloverStrategy build() { maxIndex = DEFAULT_MAX_FILES; } } + final Map compressionOptions = compressionLevel != null + ? Map.of(CompressActionFactory.COMPRESSION_LEVEL, compressionLevel) + : Map.of(); return new DirectWriteRolloverStrategy( maxIndex, - Map.of(CompressActionFactory.COMPRESSION_LEVEL, compressionLevel), + compressionOptions, config.getStrSubstitutor(), customActions, stopCustomActionsOnError,