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 1010 <Appenders >
1111 <Console name =" Console" target =" SYSTEM_OUT" follow =" true" >
1212 <Select >
13+ <SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" propertyValue =" " >
14+ <PatternLayout pattern =" ${sys:CONSOLE_LOG_PATTERN}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
15+ </SystemPropertyArbiter >
1316 <SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" >
1417 <StructuredLogLayout format =" ${sys:CONSOLE_LOG_STRUCTURED_FORMAT}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
1518 </SystemPropertyArbiter >
2326 </Console >
2427 <RollingFile name =" File" fileName =" ${sys:LOG_FILE}" filePattern =" ${sys:LOG_PATH}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd-HH}-%i.log.gz" >
2528 <Select >
29+ <SystemPropertyArbiter propertyName =" FILE_LOG_STRUCTURED_FORMAT" propertyValue =" " >
30+ <PatternLayout pattern =" ${sys:FILE_LOG_PATTERN}" charset =" ${sys:FILE_LOG_CHARSET}" />
31+ </SystemPropertyArbiter >
2632 <SystemPropertyArbiter propertyName =" FILE_LOG_STRUCTURED_FORMAT" >
2733 <StructuredLogLayout format =" ${sys:FILE_LOG_STRUCTURED_FORMAT}" charset =" ${sys:FILE_LOG_CHARSET}" />
2834 </SystemPropertyArbiter >
Original file line number Diff line number Diff line change 1010 <Appenders >
1111 <Console name =" Console" target =" SYSTEM_OUT" follow =" true" >
1212 <Select >
13+ <SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" propertyValue =" " >
14+ <PatternLayout pattern =" ${sys:CONSOLE_LOG_PATTERN}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
15+ </SystemPropertyArbiter >
1316 <SystemPropertyArbiter propertyName =" CONSOLE_LOG_STRUCTURED_FORMAT" >
1417 <StructuredLogLayout format =" ${sys:CONSOLE_LOG_STRUCTURED_FORMAT}" charset =" ${sys:CONSOLE_LOG_CHARSET}" />
1518 </SystemPropertyArbiter >
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2012-2023 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3232 *
3333 * @author Andy Wilkinson
3434 * @author Scott Frederick
35+ * @author Yanming Zhou
3536 */
3637class Log4j2FileXmlTests extends Log4j2XmlTests {
3738
@@ -80,6 +81,12 @@ void whenLogDateformatPatternIsSetThenFileAppenderUsesIt() {
8081 () -> assertThat (fileAppenderPattern ()).contains ("dd-MM-yyyy" ));
8182 }
8283
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+
8390 @ Override
8491 protected String getConfigFileName () {
8592 return "log4j2-file.xml" ;
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2012-2023 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3636 *
3737 * @author Andy Wilkinson
3838 * @author Scott Frederick
39+ * @author Yanming Zhou
3940 */
4041class Log4j2XmlTests {
4142
@@ -79,6 +80,12 @@ void whenLogDateformatPatternIsSetThenConsoleUsesIt() {
7980 () -> assertThat (consolePattern ()).contains ("dd-MM-yyyy" ));
8081 }
8182
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+
8289 protected void withSystemProperty (String name , String value , Runnable action ) {
8390 String previous = System .setProperty (name , value );
8491 action .run ();
You can’t perform that action at this time.
0 commit comments