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 17
17
package org .apache .logging .log4j .core .config ;
18
18
19
19
import java .io .IOException ;
20
- import java .nio .file .Files ;
21
20
import java .nio .file .Path ;
22
- import java .nio .file .Paths ;
23
21
24
22
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 ;
26
24
import org .junit .jupiter .api .Test ;
27
25
28
- import static org .junit . jupiter .api .Assertions .assertTrue ;
26
+ import static org .assertj . core .api .Assertions .assertThat ;
29
27
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
+ */
31
31
public class FileOutputTest {
32
32
33
+ @ TempLoggingDir
34
+ private static Path loggingPath ;
35
+
33
36
@ Test
34
- @ LoggerContextSource ( value = "classpath:log4j-filetest.xml" )
37
+ @ LoggerContextSource
35
38
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 ();
39
41
}
40
42
41
43
}
Original file line number Diff line number Diff line change 15
15
~ See the License for the specific language governing permissions and
16
16
~ limitations under the License.
17
17
-->
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" >
24
19
<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" />
38
21
</Appenders >
39
22
40
23
<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" >
53
25
<AppenderRef ref =" STDOUT" />
54
26
</Root >
55
27
</Loggers >
You can’t perform that action at this time.
0 commit comments