File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed
spring-boot-project/spring-boot/src
main/resources/org/springframework/boot/logging/log4j2
test/java/org/springframework/boot/logging/log4j2 Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 10
10
<Appenders >
11
11
<Console name =" Console" target =" SYSTEM_OUT" follow =" true" >
12
12
<Select >
13
+ <SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" propertyValue =" " >
14
+ <PatternLayout pattern =" ${sys:CONSOLE_LOG_PATTERN}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
15
+ </SystemPropertyArbiter >
13
16
<SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" >
14
17
<StructuredLogLayout format =" ${sys:CONSOLE_LOG_STRUCTURED_FORMAT}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
15
18
</SystemPropertyArbiter >
23
26
</Console >
24
27
<RollingFile name =" File" fileName =" ${sys:LOG_FILE}" filePattern =" ${sys:LOG_PATH}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd-HH}-%i.log.gz" >
25
28
<Select >
29
+ <SystemPropertyArbiter propertyName =" FILE_LOG_STRUCTURED_FORMAT" propertyValue =" " >
30
+ <PatternLayout pattern =" ${sys:FILE_LOG_PATTERN}" charset =" ${sys:FILE_LOG_CHARSET}" />
31
+ </SystemPropertyArbiter >
26
32
<SystemPropertyArbiter propertyName =" FILE_LOG_STRUCTURED_FORMAT" >
27
33
<StructuredLogLayout format =" ${sys:FILE_LOG_STRUCTURED_FORMAT}" charset =" ${sys:FILE_LOG_CHARSET}" />
28
34
</SystemPropertyArbiter >
Original file line number Diff line number Diff line change 10
10
<Appenders >
11
11
<Console name =" Console" target =" SYSTEM_OUT" follow =" true" >
12
12
<Select >
13
+ <SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" propertyValue =" " >
14
+ <PatternLayout pattern =" ${sys:CONSOLE_LOG_PATTERN}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
15
+ </SystemPropertyArbiter >
13
16
<SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" >
14
17
<StructuredLogLayout format =" ${sys:CONSOLE_LOG_STRUCTURED_FORMAT}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
15
18
</SystemPropertyArbiter >
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2012-2023 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
32
32
*
33
33
* @author Andy Wilkinson
34
34
* @author Scott Frederick
35
+ * @author Yanming Zhou
35
36
*/
36
37
class Log4j2FileXmlTests extends Log4j2XmlTests {
37
38
@@ -80,6 +81,12 @@ void whenLogDateformatPatternIsSetThenFileAppenderUsesIt() {
80
81
() -> assertThat (fileAppenderPattern ()).contains ("dd-MM-yyyy" ));
81
82
}
82
83
84
+ @ Test
85
+ void whenFileLogStructuredFormatIsEmptyThenFallbackToPatternLayout () {
86
+ withSystemProperty (LoggingSystemProperty .FILE_STRUCTURED_FORMAT .getEnvironmentVariableName (), "" ,
87
+ () -> assertThat (fileAppenderPattern ()).contains ("yyyy-MM-dd'T'HH:mm:ss.SSSXXX" ));
88
+ }
89
+
83
90
@ Override
84
91
protected String getConfigFileName () {
85
92
return "log4j2-file.xml" ;
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2012-2023 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
36
36
*
37
37
* @author Andy Wilkinson
38
38
* @author Scott Frederick
39
+ * @author Yanming Zhou
39
40
*/
40
41
class Log4j2XmlTests {
41
42
@@ -79,6 +80,12 @@ void whenLogDateformatPatternIsSetThenConsoleUsesIt() {
79
80
() -> assertThat (consolePattern ()).contains ("dd-MM-yyyy" ));
80
81
}
81
82
83
+ @ Test
84
+ void whenConsoleStructuredFormatIsEmptyThenFallbackToPatternLayout () {
85
+ withSystemProperty (LoggingSystemProperty .CONSOLE_STRUCTURED_FORMAT .getEnvironmentVariableName (), "" ,
86
+ () -> assertThat (consolePattern ()).contains ("yyyy-MM-dd'T'HH:mm:ss.SSSXXX" ));
87
+ }
88
+
82
89
protected void withSystemProperty (String name , String value , Runnable action ) {
83
90
String previous = System .setProperty (name , value );
84
91
action .run ();
You can’t perform that action at this time.
0 commit comments