Skip to content

Commit 7d45989

Browse files
committed
Fix FileOutputTest on Windows
1 parent 992db8b commit 7d45989

File tree

2 files changed

+14
-40
lines changed

2 files changed

+14
-40
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,27 @@
1717
package org.apache.logging.log4j.core.config;
1818

1919
import java.io.IOException;
20-
import java.nio.file.Files;
2120
import java.nio.file.Path;
22-
import java.nio.file.Paths;
2321

2422
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
25-
import org.apache.logging.log4j.test.junit.CleanUpFiles;
23+
import org.apache.logging.log4j.test.junit.TempLoggingDir;
2624
import org.junit.jupiter.api.Test;
2725

28-
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
import static org.assertj.core.api.Assertions.assertThat;
2927

30-
@CleanUpFiles("target/test.log") // File name MUST match the one in log4j-filetest.xml.
28+
/**
29+
* Tests the possibility to redirect status logger output to a file.
30+
*/
3131
public class FileOutputTest {
3232

33+
@TempLoggingDir
34+
private static Path loggingPath;
35+
3336
@Test
34-
@LoggerContextSource(value="classpath:log4j-filetest.xml")
37+
@LoggerContextSource
3538
public void testConfig() throws IOException {
36-
final Path logFile = Paths.get("target", "status.log");
37-
assertTrue(Files.exists(logFile), "Status output file does not exist");
38-
assertTrue(Files.size(logFile) > 0, "File is empty");
39+
final Path logFile = loggingPath.resolve("status.log");
40+
assertThat(logFile).exists().isNotEmptyFile();
3941
}
4042

4143
}

log4j-core-test/src/test/resources/log4j-filetest.xml renamed to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/FileOutputTest.xml

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,13 @@
1515
~ See the License for the specific language governing permissions and
1616
~ limitations under the License.
1717
-->
18-
<Configuration status="warn" dest="target/status.log" name="XMLConfigTest">
19-
<Properties>
20-
<Property name="filename">target/test.log</Property>
21-
</Properties>
22-
<ThresholdFilter level="debug"/>
23-
18+
<Configuration status="DEBUG" dest="${test:logging.path}/status.log" name="FileOutputTest">
2419
<Appenders>
25-
<Console name="STDOUT">
26-
<PatternLayout pattern="%m%n"/>
27-
</Console>
28-
<File name="File" fileName="${filename}" bufferedIO="false">
29-
<PatternLayout>
30-
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
31-
</PatternLayout>
32-
</File>
33-
<List name="List">
34-
<Filters>
35-
<ThresholdFilter level="error"/>
36-
</Filters>
37-
</List>
20+
<Console name="STDOUT"/>
3821
</Appenders>
3922

4023
<Loggers>
41-
<Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
42-
<ThreadContextMapFilter>
43-
<KeyValuePair key="test" value="123"/>
44-
</ThreadContextMapFilter>
45-
<AppenderRef ref="STDOUT"/>
46-
</Logger>
47-
48-
<Logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
49-
<AppenderRef ref="File"/>
50-
</Logger>
51-
52-
<Root level="error">
24+
<Root level="ERROR">
5325
<AppenderRef ref="STDOUT"/>
5426
</Root>
5527
</Loggers>

0 commit comments

Comments
 (0)