File tree Expand file tree Collapse file tree 2 files changed +14
-40
lines changed
java/org/apache/logging/log4j/core/config
resources/org/apache/logging/log4j/core/config Expand file tree Collapse file tree 2 files changed +14
-40
lines changed Original file line number Diff line number Diff line change 1717package org .apache .logging .log4j .core .config ;
1818
1919import java .io .IOException ;
20- import java .nio .file .Files ;
2120import java .nio .file .Path ;
22- import java .nio .file .Paths ;
2321
2422import 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 ;
2624import 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+ */
3131public 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}
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments