diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java index 36e03de75392..6a53f20e0ddd 100644 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java +++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java @@ -19,27 +19,31 @@ import static org.apache.logging.log4j.core.config.ConfigurationFactory.LOG4J1_CONFIGURATION_FILE_PROPERTY; import static org.assertj.core.api.Assertions.assertThat; -import java.nio.file.Paths; +import java.nio.file.Path; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.SetSystemProperty; +import org.junitpioneer.jupiter.RestoreSystemProperties; /** * Test configuration from Properties. */ -public class PropertiesRollingWithPropertiesTest { +class PropertiesRollingWithPropertiesTest { - private static final String TEST_DIR = "target/PropertiesRollingWithPropertiesTest"; + @TempLoggingDir + private static Path loggingPath; @Test - @SetSystemProperty(key = "test.directory", value = TEST_DIR) - @SetSystemProperty(key = LOG4J1_CONFIGURATION_FILE_PROPERTY, value = "log4j1-rolling-properties.properties") - @CleanUpDirectories(TEST_DIR) - public void testProperties() throws Exception { - final Logger logger = LoggerContext.getContext(false).getLogger("test"); - logger.debug("This is a test of the root logger"); - assertThat(Paths.get(TEST_DIR, "somefile.log")).exists().isNotEmptyFile(); + @RestoreSystemProperties + void testProperties() { + System.setProperty("test.directory", loggingPath.toString()); + System.setProperty(LOG4J1_CONFIGURATION_FILE_PROPERTY, "log4j1-rolling-properties.properties"); + + try (final LoggerContext context = LoggerContext.getContext(false)) { + final Logger logger = context.getLogger("test"); + logger.debug("This is a test of the root logger"); + assertThat(loggingPath.resolve("somefile.log")).exists().isNotEmptyFile(); + } } } diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java index 2dc5a4434de2..6954c452a6b7 100644 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java +++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java @@ -19,28 +19,31 @@ import static org.apache.logging.log4j.core.config.ConfigurationFactory.LOG4J1_CONFIGURATION_FILE_PROPERTY; import static org.assertj.core.api.Assertions.assertThat; -import java.nio.file.Paths; +import java.nio.file.Path; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.SetSystemProperty; +import org.junitpioneer.jupiter.RestoreSystemProperties; /** - * Test configuration from Properties. + * Test configuration from XML. */ -public class XmlRollingWithPropertiesTest { +class XmlRollingWithPropertiesTest { - private static final String TEST_DIR = "target/XmlRollingWithPropertiesTest"; + @TempLoggingDir + private static Path loggingPath; @Test - @SetSystemProperty(key = "test.directory", value = TEST_DIR) - @SetSystemProperty(key = LOG4J1_CONFIGURATION_FILE_PROPERTY, value = "log4j1-rolling-properties.xml") - @CleanUpDirectories(TEST_DIR) - public void testProperties() { - // ${test.directory}/logs/etl.log - final Logger logger = LoggerContext.getContext(false).getLogger("test"); - logger.debug("This is a test of the root logger"); - assertThat(Paths.get(TEST_DIR, "logs/etl.log")).exists().isNotEmptyFile(); + @RestoreSystemProperties + void testProperties() { + System.setProperty("test.directory", loggingPath.toString()); + System.setProperty(LOG4J1_CONFIGURATION_FILE_PROPERTY, "log4j1-rolling-properties.xml"); + + try (final LoggerContext context = LoggerContext.getContext(false)) { + final Logger logger = context.getLogger("test"); + logger.debug("This is a test of the root logger"); + assertThat(loggingPath.resolve("logs/etl.log")).exists().isNotEmptyFile(); + } } } diff --git a/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties b/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties index 5d6dbde2d5ea..0e856c9b627b 100644 --- a/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties +++ b/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties @@ -15,8 +15,6 @@ # limitations under the License. # -log4j.debug=true - # Properties for substitution somelogfile=somefile.log maxfilesize=256MB diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2DirectTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2DirectTest.java index 30ddf91add00..bafd100495e9 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2DirectTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2DirectTest.java @@ -24,23 +24,19 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RollingAppenderCronEvery2DirectTest extends AbstractRollingListenerTest { +class RollingAppenderCronEvery2DirectTest extends AbstractRollingListenerTest { - private static final String CONFIG = "log4j-rolling-cron-every2-direct.xml"; - private static final String DIR = "target/rolling-cron-every2Direct"; private final CountDownLatch rollover = new CountDownLatch(2); + @TempLoggingDir + private static Path loggingPath; + @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 10) - public void testAppender(final Logger logger, @Named("RollingFile") final RollingFileManager manager) - throws Exception { + @LoggerContextSource(timeout = 10) + void testAppender(final Logger logger, @Named("RollingFile") final RollingFileManager manager) throws Exception { manager.addRolloverListener(this); final long end = currentTimeMillis.get() + 5000; final Random rand = new Random(end); @@ -51,9 +47,7 @@ public void testAppender(final Logger logger, @Named("RollingFile") final Rollin } while (currentTimeMillis.get() < end); rollover.await(); - final Path dir = Path.of(DIR); - assertThat(dir).isNotEmptyDirectory(); - assertThat(dir).isDirectoryContaining("glob:**.gz"); + assertThat(loggingPath).isNotEmptyDirectory().isDirectoryContaining("glob:**.gz"); } @Override diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2Test.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2Test.java index 4f9d1293434b..e5c18423e02c 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2Test.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2Test.java @@ -24,26 +24,21 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RollingAppenderCronEvery2Test extends AbstractRollingListenerTest { +class RollingAppenderCronEvery2Test extends AbstractRollingListenerTest { - private static final String CONFIG = "log4j-rolling-cron-every2.xml"; - private static final String DIR = "target/rolling-cron-every2"; - private static final String FILE = "target/rolling-cron-every2/rollingtest.log"; private final CountDownLatch rollover = new CountDownLatch(3); + @TempLoggingDir + private static Path loggingPath; + @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 10) - public void testAppender(final Logger logger, @Named("RollingFile") final RollingFileManager manager) - throws Exception { + @LoggerContextSource(timeout = 10) + void testAppender(final Logger logger, @Named("RollingFile") final RollingFileManager manager) throws Exception { manager.addRolloverListener(this); - assertThat(Path.of(FILE)).exists(); + assertThat(loggingPath.resolve("rollingtest.log")).exists(); final long end = currentTimeMillis.get() + 5000; final Random rand = new Random(end); int count = 1; @@ -53,11 +48,7 @@ public void testAppender(final Logger logger, @Named("RollingFile") final Rollin } while (currentTimeMillis.get() < end); rollover.await(); - - final Path dir = Path.of(DIR); - assertThat(dir).exists(); - assertThat(dir).isNotEmptyDirectory(); - assertThat(dir).isDirectoryContaining("glob:**.gz"); + assertThat(loggingPath).isNotEmptyDirectory().isDirectoryContaining("glob:**.gz"); } @Override diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java index ab9abe9ca7c5..3370eea5b28d 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -27,36 +26,22 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.status.StatusData; -import org.apache.logging.log4j.status.StatusListener; -import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; -import org.junit.jupiter.api.BeforeAll; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RollingAppenderDirectWrite1906Test implements RolloverListener { - - private static final String CONFIG = "log4j-rolling-direct-1906.xml"; +class RollingAppenderDirectWrite1906Test implements RolloverListener { - private static final String DIR = "target/rolling-direct-1906"; private final CountDownLatch rollover = new CountDownLatch(2); - @BeforeAll - static void beforeAll() { - StatusLogger.getLogger().registerListener(new NoopStatusListener()); - } + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 10) - public void testAppender(final LoggerContext context, @Named("RollingFile") final RollingFileManager manager) + @LoggerContextSource(timeout = 10) + void testAppender(final LoggerContext context, @Named("RollingFile") final RollingFileManager manager) throws Exception { manager.addRolloverListener(this); final var logger = context.getLogger(getClass()); @@ -66,11 +51,10 @@ public void testAppender(final LoggerContext context, @Named("RollingFile") fina Thread.sleep(50); } rollover.await(); - final Path dir = Path.of(DIR); - assertThat(dir).isNotEmptyDirectory(); - assertThat(dir).isDirectoryContaining("glob:**.log"); + assertThat(loggingPath).isNotEmptyDirectory(); + assertThat(loggingPath).isDirectoryContaining("glob:**.log"); - try (final Stream files = Files.list(dir)) { + try (final Stream files = Files.list(loggingPath)) { final AtomicInteger found = new AtomicInteger(); assertThat(files).allSatisfy(file -> { final String expected = file.getFileName().toString(); @@ -96,17 +80,4 @@ public void rolloverTriggered(final String fileName) {} public void rolloverComplete(final String fileName) { rollover.countDown(); } - - private static class NoopStatusListener implements StatusListener { - @Override - public void log(final StatusData data) {} - - @Override - public Level getStatusLevel() { - return Level.TRACE; - } - - @Override - public void close() throws IOException {} - } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java index d7963423f011..ef837ff46ed6 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java @@ -18,31 +18,31 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.concurrent.CountDownLatch; +import java.util.stream.Stream; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.appender.RollingFileAppender; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RollingAppenderDirectWriteWithReconfigureTest extends AbstractRollingListenerTest { +class RollingAppenderDirectWriteWithReconfigureTest extends AbstractRollingListenerTest { - private static final String CONFIG = "log4j-rolling-direct-reconfigure.xml"; - - private static final String DIR = "target/rolling-direct-reconfigure"; + private static final String CONFIG = + "org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.xml"; private final CountDownLatch rollover = new CountDownLatch(1); + @TempLoggingDir + private static Path loggingPath; + @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 10) - public void testRollingFileAppenderWithReconfigure(final LoggerContext context) throws Exception { + @LoggerContextSource(timeout = 10) + void testRollingFileAppenderWithReconfigure(final LoggerContext context) throws Exception { final var logger = context.getLogger(getClass()); logger.debug("Before reconfigure"); @@ -53,9 +53,10 @@ public void testRollingFileAppenderWithReconfigure(final LoggerContext context) appender.getManager().addRolloverListener(this); logger.debug("Force a rollover"); rollover.await(); - final File dir = new File(DIR); - assertThat(dir).isNotEmptyDirectory(); - assertThat(dir.listFiles()).hasSize(2); + assertThat(loggingPath).isNotEmptyDirectory(); + try (final Stream files = Files.list(loggingPath)) { + assertThat(files).as("check log file count").hasSize(2); + } } @Override diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeDirectTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeDirectTest.java index 34a5f98c2bb9..ff09cd9a20ef 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeDirectTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeDirectTest.java @@ -16,44 +16,31 @@ */ package org.apache.logging.log4j.core.appender.rolling; -import static org.apache.logging.log4j.core.test.hamcrest.Descriptors.that; -import static org.apache.logging.log4j.core.test.hamcrest.FileMatchers.hasName; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.hasItemInArray; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; +import java.nio.file.Path; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; -import org.junit.jupiter.api.Tag; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -@Tag("sleepy") -public class RollingAppenderTimeAndSizeDirectTest { - - private static final String CONFIG = "log4j-rolling3-direct.xml"; +class RollingAppenderTimeAndSizeDirectTest { - private static final String DIR = "target/rolling3Direct"; + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 10) - public void testAppender(final Logger logger) throws Exception { + @LoggerContextSource(timeout = 10) + void testAppender(final Logger logger) throws Exception { for (int i = 0; i < 100; ++i) { logger.debug("This is test message number " + i); Thread.sleep(10); } Thread.sleep(50); - final File dir = new File(DIR); - assertTrue(dir.exists() && dir.listFiles().length > 0, "Directory not created"); - final File[] files = dir.listFiles(); - assertNotNull(files); - assertThat(files, hasItemInArray(that(hasName(that(endsWith(".gz")))))); + assertThat(loggingPath) + .as("check logging directory") + .isNotEmptyDirectory() + .as("check contains compressed log file") + .isDirectoryContaining("glob:**.gz"); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.java index 7bde5d3988a7..8c9bc32e7b90 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.java @@ -16,42 +16,33 @@ */ package org.apache.logging.log4j.core.appender.rolling; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; +import java.nio.file.Path; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RollingAppenderUncompressedTest { +class RollingAppenderUncompressedTest { - private static final String CONFIG = "log4j-rolling4.xml"; + private static final String CONFIG = + "org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.xml"; private static final String DIR = "target/rolling4"; + @TempLoggingDir + private static Path loggingPath; + @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(CONFIG) - public void testAppender(final Logger logger) throws Exception { + @LoggerContextSource + void testAppender(final Logger logger) throws Exception { for (int i = 0; i < 100; ++i) { logger.debug("This is test message number " + i); } - final File dir = new File(DIR); - assertTrue(dir.exists() && dir.listFiles().length > 0, "Directory not created"); - final File[] files = dir.listFiles(); - assertNotNull(files); - boolean found = false; - for (final File file : files) { - final String name = file.getName(); - if (name.startsWith("test1") && name.endsWith(".log")) { - found = true; - break; - } - } - assertTrue(found, "No archived files found"); + assertThat(loggingPath) + .as("check logging directory") + .isNotEmptyDirectory() + .as("check contains not compressed log file") + .isDirectoryContaining("glob:**/test1*.log"); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java index 4da44ab6aaeb..782056fd7969 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java @@ -17,36 +17,32 @@ package org.apache.logging.log4j.core.appender.rolling; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.File; -import java.util.Arrays; -import java.util.Iterator; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; import java.util.concurrent.CountDownLatch; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.filefilter.TrueFileFilter; +import java.util.stream.Stream; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -import org.opentest4j.AssertionFailedError; -public class RollingDirectTimeNewDirectoryTest implements RolloverListener { +class RollingDirectTimeNewDirectoryTest implements RolloverListener { - private static final String CONFIG = "log4j-rolling-folder-direct.xml"; - - // Note that the path is hardcoded in the configuration! - private static final String DIR = "target/rolling-folder-direct"; private final CountDownLatch rollover = new CountDownLatch(2); private boolean isFirst = true; private String ignored = null; + @TempLoggingDir + private Path loggingPath; + @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 15) - public void streamClosedError(final LoggerContext context, @Named("RollingFile") final RollingFileManager manager) + @LoggerContextSource(timeout = 15) + void streamClosedError(final LoggerContext context, @Named("RollingFile") final RollingFileManager manager) throws Exception { manager.addRolloverListener(this); @@ -68,48 +64,22 @@ public void streamClosedError(final LoggerContext context, @Named("RollingFile") rollover.await(); - final File logDir = new File(DIR); - assertThat(logDir).isNotEmptyDirectory(); - final File[] logFolders = logDir.listFiles(); - assertNotNull(logFolders); - Arrays.sort(logFolders); - - try { - - final int minExpectedLogFolderCount = 2; - assertThat(logFolders).hasSizeGreaterThanOrEqualTo(minExpectedLogFolderCount); + assertThat(loggingPath).isNotEmptyDirectory(); + final List logFolders; + try (final Stream files = Files.list(loggingPath)) { + logFolders = files.sorted().toList(); + } - for (File logFolder : logFolders) { - // It is possible a log file is created at startup and by he time we get here it - // has rolled but has no data and so was deleted. - if (ignored != null && logFolder.getAbsolutePath().equals(ignored)) { - continue; - } - final File[] logFiles = logFolder.listFiles(); - if (logFiles != null) { - Arrays.sort(logFiles); - } - assertThat(logFiles).isNotEmpty(); - } + final int minExpectedLogFolderCount = 2; + assertThat(logFolders).hasSizeGreaterThanOrEqualTo(minExpectedLogFolderCount); - } catch (AssertionError error) { - final StringBuilder sb = new StringBuilder(error.getMessage()) - .append(" log directory (") - .append(DIR) - .append(") contents: ["); - final Iterator fileIterator = - FileUtils.iterateFilesAndDirs(logDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE); - int totalFileCount = 0; - while (fileIterator.hasNext()) { - totalFileCount++; - final File file = fileIterator.next(); - sb.append("-> ").append(file).append(" (").append(file.length()).append(')'); - if (fileIterator.hasNext()) { - sb.append(", "); - } + for (final Path logFolder : logFolders) { + // It is possible a log file is created at startup and by he time we get here it + // has rolled but has no data and so was deleted. + if (logFolder.toAbsolutePath().toString().equals(ignored)) { + continue; } - sb.append("] total file count: ").append(totalFileCount); - throw new AssertionFailedError(sb.toString(), error); + assertThat(logFolder).isNotEmptyDirectory(); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingNewDirectoryTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingNewDirectoryTest.java index 766869278a07..3452a79b7194 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingNewDirectoryTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingNewDirectoryTest.java @@ -19,27 +19,26 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * Tests - */ -public class RollingNewDirectoryTest implements RolloverListener { - private static final String CONFIG = "log4j-rolling-new-directory.xml"; +class RollingNewDirectoryTest implements RolloverListener { - private static final String DIR = "target/rolling-new-directory"; private final CountDownLatch rollover = new CountDownLatch(3); + @TempLoggingDir + private Path loggingPath; + @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 10) + @LoggerContextSource(timeout = 10) public void streamClosedError(final Logger logger, @Named("RollingFile") final RollingFileManager manager) throws Exception { manager.addRolloverListener(this); @@ -54,9 +53,10 @@ public void streamClosedError(final Logger logger, @Named("RollingFile") final R } catch (InterruptedException ie) { fail("Thread was interrupted"); } - final File dir = new File(DIR); - assertThat(dir).isNotEmptyDirectory(); - assertThat(dir.listFiles()).hasSizeGreaterThan(2); + assertThat(loggingPath).isNotEmptyDirectory(); + try (final Stream files = Files.list(loggingPath)) { + assertThat(files).hasSizeGreaterThan(2); + } } @Override diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAppenderDirectWriteTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAppenderDirectWriteTest.java index cc1924e29f1e..5d66edbef88c 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAppenderDirectWriteTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAppenderDirectWriteTest.java @@ -16,45 +16,28 @@ */ package org.apache.logging.log4j.core.appender.rolling; -import static org.apache.logging.log4j.core.test.hamcrest.Descriptors.that; -import static org.apache.logging.log4j.core.test.hamcrest.FileMatchers.hasName; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasItemInArray; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; +import java.nio.file.Path; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; -import org.apache.logging.log4j.test.junit.CleanUpDirectories; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -/** - * - */ @Tag("sleepy") -public class RollingRandomAppenderDirectWriteTest { - - private static final String CONFIG = "log4j-rolling-random-direct.xml"; +class RollingRandomAppenderDirectWriteTest { - private static final String DIR = "target/rolling-random-direct"; + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpDirectories(DIR) - @LoggerContextSource(value = CONFIG, timeout = 10) - public void testAppender(final Logger logger) throws Exception { + @LoggerContextSource(timeout = 10) + void testAppender(final Logger logger) throws Exception { for (int i = 0; i < 100; ++i) { logger.debug("This is test message number " + i); } Thread.sleep(50); - final File dir = new File(DIR); - assertTrue(dir.exists(), "Directory not created"); - final File[] files = dir.listFiles(); - assertNotNull(files); - assertThat(files.length, greaterThan(0)); - assertThat(files, hasItemInArray(that(hasName(that(endsWith(".gz")))))); + assertThat(loggingPath).isNotEmptyDirectory().isDirectoryContaining("glob:**.gz"); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.java index 409179245653..8e2f12f9ce13 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.java @@ -16,11 +16,11 @@ */ package org.apache.logging.log4j.core.appender.routing; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.File; +import java.nio.file.Path; import java.util.List; import org.apache.logging.log4j.EventLogger; import org.apache.logging.log4j.core.LogEvent; @@ -28,20 +28,18 @@ import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.message.StructuredDataMessage; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpFiles; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class JsonRoutingAppender2Test { - private static final String CONFIG = "log4j-routing2.json"; - private static final String LOG_FILENAME = "target/rolling1/rollingtest-Unknown.log"; +class JsonRoutingAppender2Test { + private static final String CONFIG = "org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.json"; + + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpFiles(LOG_FILENAME) @LoggerContextSource(CONFIG) - public void routingTest(@Named("List") final ListAppender appender) { + void routingTest(@Named("List") final ListAppender appender) { StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service"); EventLogger.logEvent(msg); final List list = appender.getEvents(); @@ -49,7 +47,6 @@ public void routingTest(@Named("List") final ListAppender appender) { assertEquals(1, list.size(), "Incorrect number of events. Expected 1, got " + list.size()); msg = new StructuredDataMessage("Test", "This is a test", "Unknown"); EventLogger.logEvent(msg); - final File file = new File(LOG_FILENAME); - assertTrue(file.exists(), "File was not created"); + assertThat(loggingPath.resolve("rollingtest-Unknown.log")).exists(); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.java index cc3cdf3ed7f8..24eb852f3e1c 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.java @@ -16,11 +16,11 @@ */ package org.apache.logging.log4j.core.appender.routing; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.File; +import java.nio.file.Path; import java.util.List; import org.apache.logging.log4j.EventLogger; import org.apache.logging.log4j.core.LogEvent; @@ -28,20 +28,18 @@ import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.message.StructuredDataMessage; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpFiles; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class JsonRoutingAppenderTest { - private static final String CONFIG = "log4j-routing.json"; - private static final String LOG_FILENAME = "target/rolling1/rollingtest-Unknown.log"; +class JsonRoutingAppenderTest { + private static final String CONFIG = "org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.json"; + + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpFiles(LOG_FILENAME) @LoggerContextSource(CONFIG) - public void routingTest(@Named("List") final ListAppender appender) { + void routingTest(@Named("List") final ListAppender appender) { StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service"); EventLogger.logEvent(msg); final List list = appender.getEvents(); @@ -49,7 +47,6 @@ public void routingTest(@Named("List") final ListAppender appender) { assertEquals(1, list.size(), "Incorrect number of events. Expected 1, got " + list.size()); msg = new StructuredDataMessage("Test", "This is a test", "Unknown"); EventLogger.logEvent(msg); - final File file = new File(LOG_FILENAME); - assertTrue(file.exists(), "File was not created"); + assertThat(loggingPath.resolve("rollingtest-Unknown.log")).exists(); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender2767Test.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender2767Test.java index 66c06ebc3d03..51c0e24f4254 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender2767Test.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender2767Test.java @@ -16,36 +16,32 @@ */ package org.apache.logging.log4j.core.appender.routing; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; -import java.nio.file.Files; -import java.util.List; -import java.util.stream.Collectors; +import java.nio.file.Path; import org.apache.logging.log4j.EventLogger; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.message.StructuredDataMessage; -import org.apache.logging.log4j.test.junit.CleanUpFiles; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RoutingAppender2767Test { - private static final String CONFIG = "log4j-routing-2767.xml"; - private static final String ACTIVITY_LOG_FILE = "target/routing1/routingtest-Service.log"; +class RoutingAppender2767Test { + private static final String ACTIVITY_LOG_FILE = "routingtest-Service.log"; + + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpFiles(ACTIVITY_LOG_FILE) - @LoggerContextSource(CONFIG) - public void routingTest() throws Exception { + @LoggerContextSource + public void routingTest() { final StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service"); EventLogger.logEvent(msg); - final File file = new File(ACTIVITY_LOG_FILE); - assertTrue(file.exists(), "Activity file was not created"); - final List lines = Files.lines(file.toPath()).collect(Collectors.toList()); - assertEquals(1, lines.size(), "Incorrect number of lines"); - assertTrue(lines.get(0).contains("This is a test"), "Incorrect content"); + assertThat(loggingPath.resolve(ACTIVITY_LOG_FILE)) + .as("check 'Activity' log file") + .exists() + .content() + .as("check 'Activity' log file content") + .hasLineCount(1) + .contains("This is a test"); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java index 894a6a16aac0..438b42828808 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java @@ -16,11 +16,11 @@ */ package org.apache.logging.log4j.core.appender.routing; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.File; +import java.nio.file.Path; import java.util.List; import org.apache.logging.log4j.EventLogger; import org.apache.logging.log4j.core.LogEvent; @@ -28,22 +28,19 @@ import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.message.StructuredDataMessage; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpFiles; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RoutingAppenderTest { - private static final String CONFIG = "log4j-routing.xml"; - private static final String UNKNOWN_LOG_FILE = "target/rolling1/rollingtest-Unknown.log"; - private static final String ALERT_LOG_FILE = "target/routing1/routingtest-Alert.log"; - private static final String ACTIVITY_LOG_FILE = "target/routing1/routingtest-Activity.log"; +class RoutingAppenderTest { + private static final String ALERT_LOG_FILE = "routingtest-Alert.log"; + private static final String ACTIVITY_LOG_FILE = "routingtest-Activity.log"; + + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpFiles({UNKNOWN_LOG_FILE, ALERT_LOG_FILE, ACTIVITY_LOG_FILE}) - @LoggerContextSource(CONFIG) - public void routingTest(@Named("List") final ListAppender app) { + @LoggerContextSource + void routingTest(@Named("List") final ListAppender app) { StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service"); EventLogger.logEvent(msg); final List list = app.getEvents(); @@ -51,11 +48,14 @@ public void routingTest(@Named("List") final ListAppender app) { assertEquals(1, list.size(), "Incorrect number of events. Expected 1, got " + list.size()); msg = new StructuredDataMessage("Test", "This is a test", "Alert"); EventLogger.logEvent(msg); - File file = new File(ALERT_LOG_FILE); - assertTrue(file.exists(), "Alert file was not created"); + assertThat(loggingPath.resolve(ALERT_LOG_FILE)) + .as("check 'Alert' log file") + .exists(); + msg = new StructuredDataMessage("Test", "This is a test", "Activity"); EventLogger.logEvent(msg); - file = new File(ACTIVITY_LOG_FILE); - assertTrue(file.exists(), "Activity file was not created"); + assertThat(loggingPath.resolve(ACTIVITY_LOG_FILE)) + .as("check 'Activity' log file") + .exists(); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java index d9d5a0eb5467..a18290d53ff7 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java @@ -16,11 +16,11 @@ */ package org.apache.logging.log4j.core.appender.routing; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.File; +import java.nio.file.Path; import java.util.List; import org.apache.logging.log4j.EventLogger; import org.apache.logging.log4j.core.LogEvent; @@ -28,19 +28,18 @@ import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.message.StructuredDataMessage; import org.apache.logging.log4j.plugins.Named; -import org.apache.logging.log4j.test.junit.CleanUpFiles; +import org.apache.logging.log4j.test.junit.TempLoggingDir; import org.junit.jupiter.api.Test; -/** - * - */ -public class RoutingDefaultAppenderTest { - private static final String LOG_FILE = "target/routing1/routingtest.log"; +class RoutingDefaultAppenderTest { + private static final String LOG_FILE = "routingtest.log"; + + @TempLoggingDir + private static Path loggingPath; @Test - @CleanUpFiles(LOG_FILE) - @LoggerContextSource("log4j-routing3.xml") - public void routingTest(@Named("List") final ListAppender app) { + @LoggerContextSource + void routingTest(@Named("List") final ListAppender app) { StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service"); EventLogger.logEvent(msg); final List list = app.getEvents(); @@ -48,7 +47,6 @@ public void routingTest(@Named("List") final ListAppender app) { assertEquals(1, list.size(), "Incorrect number of events. Expected 1, got " + list.size()); msg = new StructuredDataMessage("Test", "This is a test", "Alert"); EventLogger.logEvent(msg); - final File file = new File(LOG_FILE); - assertTrue(file.exists(), "Alert file was not created"); + assertThat(loggingPath.resolve(LOG_FILE)).as("check log file").exists(); } } diff --git a/log4j-core-test/src/test/resources/log4j-rolling-random-direct.xml b/log4j-core-test/src/test/resources/log4j-rolling-random-direct.xml deleted file mode 100644 index d3b43bf0fd85..000000000000 --- a/log4j-core-test/src/test/resources/log4j-rolling-random-direct.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - target/rolling-random-direct - - - - - - - - - - %d %p %C{1.} [%t] %m%n - - - - - - - - - - - - > - - - - - - - diff --git a/log4j-core-test/src/test/resources/log4j-routing.json b/log4j-core-test/src/test/resources/log4j-routing.json deleted file mode 100644 index c8b3e648868b..000000000000 --- a/log4j-core-test/src/test/resources/log4j-routing.json +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -{ "configuration": { "status": "off", "name": "RoutingTest", - "ThresholdFilter": { "level": "debug" }, - "appenders": { - "Console": { "name": "STDOUT", - "PatternLayout": { "pattern": "%m%n" } - }, - "List": { "name": "List", - "ThresholdFilter": { "level": "debug" } - }, - "Routing": { "name": "Routing", - "Routes": { "pattern": "$${sd:type}", - "Route": [ - { - "RollingFile": { - "name": "Rolling-${sd:type}", "fileName": "target/rolling1/rollingtest-${sd:type}.log", - "filePattern": "target/rolling1/test1-${sd:type}.%i.log.gz", - "PatternLayout": {"pattern": "%d %p %C{1.} [%t] %m%n"}, - "SizeBasedTriggeringPolicy": { "size": "500" } - } - }, - { "ref": "STDOUT", "key": "Audit"}, - { "ref": "List", "key": "Service"} - ] - } - } - }, - "loggers": { - "logger": { "name": "EventLogger", "level": "info", "additivity": "false", "AppenderRef": { "ref": "Routing" }}, - "root": { "level": "error", "AppenderRef": { "ref": "STDOUT" }} - } - } -} diff --git a/log4j-core-test/src/test/resources/log4j-rolling-cron-every2-direct.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2DirectTest.xml similarity index 96% rename from log4j-core-test/src/test/resources/log4j-rolling-cron-every2-direct.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2DirectTest.xml index 955f6c61566f..bc6b4b0670ae 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling-cron-every2-direct.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2DirectTest.xml @@ -17,7 +17,7 @@ --> - target/rolling-cron-every2Direct + ${test:logging.path} diff --git a/log4j-core-test/src/test/resources/log4j-rolling-cron-every2.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2Test.xml similarity index 88% rename from log4j-core-test/src/test/resources/log4j-rolling-cron-every2.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2Test.xml index 053af0078f6c..b404c638a41f 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling-cron-every2.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronEvery2Test.xml @@ -17,7 +17,7 @@ --> - target/rolling-cron-every2/rollingtest.log + ${test:logging.path}/rollingtest.log @@ -27,7 +27,8 @@ - + %d %p %C{1.} [%t] %m%n diff --git a/log4j-core-test/src/test/resources/log4j-rolling-direct-1906.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.xml similarity index 95% rename from log4j-core-test/src/test/resources/log4j-rolling-direct-1906.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.xml index 7ba34c51c9fc..e94463cc3a2a 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling-direct-1906.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.xml @@ -17,7 +17,7 @@ --> - target/rolling-direct-1906 + ${test:logging.path} diff --git a/log4j-core-test/src/test/resources/log4j-rolling-direct-reconfigure.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.xml similarity index 95% rename from log4j-core-test/src/test/resources/log4j-rolling-direct-reconfigure.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.xml index c30867af9ce1..fe6d599c4510 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling-direct-reconfigure.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.xml @@ -17,7 +17,7 @@ --> - target/rolling-direct-reconfigure + ${test:logging.path} diff --git a/log4j-core-test/src/test/resources/log4j-rolling3-direct.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeDirectTest.xml similarity index 96% rename from log4j-core-test/src/test/resources/log4j-rolling3-direct.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeDirectTest.xml index 2cecc12ec853..ba586afb4b2f 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling3-direct.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeDirectTest.xml @@ -17,7 +17,7 @@ --> - target/rolling3Direct + ${test:logging.path} diff --git a/log4j-core-test/src/test/resources/log4j-rolling4.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.xml similarity index 92% rename from log4j-core-test/src/test/resources/log4j-rolling4.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.xml index b9b6c7355737..7ea9880dc524 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling4.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderUncompressedTest.xml @@ -17,7 +17,7 @@ --> - target/rolling4/rollingtest.log + ${test:logging.path}/rollingtest.log @@ -26,7 +26,7 @@ + filePattern="${test:logging.path}/test1-$${date:MM-dd-yyyy}-%i.log"> %d %p %C{1.} [%t] %m%n diff --git a/log4j-core-test/src/test/resources/log4j-rolling-folder-direct.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.xml similarity index 95% rename from log4j-core-test/src/test/resources/log4j-rolling-folder-direct.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.xml index 7080474bcee6..5d340145fb3d 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling-folder-direct.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.xml @@ -17,7 +17,7 @@ --> - target/rolling-folder-direct + ${test:logging.path} diff --git a/log4j-core-test/src/test/resources/log4j-rolling-new-directory.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingNewDirectoryTest.xml similarity index 95% rename from log4j-core-test/src/test/resources/log4j-rolling-new-directory.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingNewDirectoryTest.xml index efd491b86c16..a117f31941a6 100644 --- a/log4j-core-test/src/test/resources/log4j-rolling-new-directory.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingNewDirectoryTest.xml @@ -17,7 +17,7 @@ --> - target/rolling-new-directory + ${test:logging.path} diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingRandomAppenderDirectWriteTest.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingRandomAppenderDirectWriteTest.xml new file mode 100644 index 000000000000..b7f259346a5c --- /dev/null +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingRandomAppenderDirectWriteTest.xml @@ -0,0 +1,50 @@ + + + + + ${test:logging.path} + + + + + + + + + + %d %p %C{1.} [%t] %m%n + + + + + + + + + + + + + > + + + + + + + diff --git a/log4j-core-test/src/test/resources/log4j-routing2.json b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.json similarity index 56% rename from log4j-core-test/src/test/resources/log4j-routing2.json rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.json index 53c7d734f565..cc9591f0fb89 100644 --- a/log4j-core-test/src/test/resources/log4j-routing2.json +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppender2Test.json @@ -1,19 +1,3 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ { "configuration": { "status": "off", "name": "RoutingTest", "ThresholdFilter": { "level": "debug" }, "appenders": { @@ -25,8 +9,8 @@ "Route": [ { "RollingFile": { - "name": "Rolling-${sd:type}", "fileName": "target/rolling1/rollingtest-${sd:type}.log", - "filePattern": "target/rolling1/test1-${sd:type}.%i.log.gz", + "name": "Rolling-${sd:type}", "fileName": "${test:logging.path}/rollingtest-${sd:type}.log", + "filePattern": "${test:logging.path}/test1-${sd:type}.%i.log.gz", "PatternLayout": {"pattern": "%d %p %C{1.} [%t] %m%n"}, "SizeBasedTriggeringPolicy": { "size": "500" } } diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.json b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.json new file mode 100644 index 000000000000..83538412263a --- /dev/null +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/JsonRoutingAppenderTest.json @@ -0,0 +1,32 @@ +{ "configuration": { "status": "off", "name": "RoutingTest", + "ThresholdFilter": { "level": "debug" }, + "appenders": { + "Console": { "name": "STDOUT", + "PatternLayout": { "pattern": "%m%n" } + }, + "List": { "name": "List", + "ThresholdFilter": { "level": "debug" } + }, + "Routing": { "name": "Routing", + "Routes": { "pattern": "$${sd:type}", + "Route": [ + { + "RollingFile": { + "name": "Rolling-${sd:type}", "fileName": "${test:logging.path}/rollingtest-${sd:type}.log", + "filePattern": "${test:logging.path}/test1-${sd:type}.%i.log.gz", + "PatternLayout": {"pattern": "%d %p %C{1.} [%t] %m%n"}, + "SizeBasedTriggeringPolicy": { "size": "500" } + } + }, + { "ref": "STDOUT", "key": "Audit"}, + { "ref": "List", "key": "Service"} + ] + } + } + }, + "loggers": { + "logger": { "name": "EventLogger", "level": "info", "additivity": "false", "AppenderRef": { "ref": "Routing" }}, + "root": { "level": "error", "AppenderRef": { "ref": "STDOUT" }} + } + } +} diff --git a/log4j-core-test/src/test/resources/log4j-routing-2767.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingAppender2767Test.xml similarity index 88% rename from log4j-core-test/src/test/resources/log4j-routing-2767.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingAppender2767Test.xml index 0fbe8f7c6208..9add4658235d 100644 --- a/log4j-core-test/src/test/resources/log4j-routing-2767.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingAppender2767Test.xml @@ -23,8 +23,8 @@ - + %d %p %C{1.} [%t] %m%n diff --git a/log4j-core-test/src/test/resources/log4j-routing.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.xml similarity index 90% rename from log4j-core-test/src/test/resources/log4j-routing.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.xml index a35ba6d0728f..115ee4f4498c 100644 --- a/log4j-core-test/src/test/resources/log4j-routing.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.xml @@ -28,8 +28,8 @@ - + %d %p %C{1.} [%t] %m%n diff --git a/log4j-core-test/src/test/resources/log4j-routing3.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.xml similarity index 92% rename from log4j-core-test/src/test/resources/log4j-routing3.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.xml index 51e5f4f79a3e..16ff85d473fe 100644 --- a/log4j-core-test/src/test/resources/log4j-routing3.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.xml @@ -17,7 +17,7 @@ --> - target/routing1/routingtest.log + ${test:logging.path}/routingtest.log @@ -29,7 +29,7 @@ + filePattern="${test:logging.path}/test1-%i.log.gz"> %d %p %C{1.} [%t] %m%n