Skip to content

Commit bae26e2

Browse files
author
Dave Syer
committed
Make sure logback console output happens early in lifecycle
The problem was that the basic-logback.xml was valid configuration but not in a <configuration> tag, so it wasn't valid on its own. This change fixes that. Fixes gh-585
1 parent d794811 commit bae26e2

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-31
lines changed

spring-boot/src/main/java/org/springframework/boot/env/PropertySourcesLoader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.List;
2323
import java.util.Set;
2424

25+
import org.apache.commons.logging.Log;
26+
import org.apache.commons.logging.LogFactory;
2527
import org.springframework.core.env.MutablePropertySources;
2628
import org.springframework.core.env.PropertySource;
2729
import org.springframework.core.io.Resource;
@@ -37,6 +39,8 @@
3739
*/
3840
public class PropertySourcesLoader {
3941

42+
private static Log logger = LogFactory.getLog(PropertySourcesLoader.class);
43+
4044
private final MutablePropertySources propertySources;
4145

4246
private final List<PropertySourceLoader> loaders;
@@ -164,6 +168,7 @@ private void addPropertySource(String basename, PropertySource<?> source,
164168

165169
EnumerableCompositePropertySource group = getGeneric(basename);
166170
group.add(source);
171+
logger.info("Adding PropertySource: " + source + " in group: " + basename);
167172
if (this.propertySources.contains(group.getName())) {
168173
this.propertySources.replace(group.getName(), group);
169174
}

spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<included>
33

4-
<include resource="org/springframework/boot/logging/logback/basic-logback.xml"/>
4+
<include resource="org/springframework/boot/logging/logback/basic.xml"/>
55

66
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${java.io.tmpdir:-/tmp}/}spring.log}"/>
77
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%t] --- %-40.40logger{39} : %m%n%wex"/>
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<included>
3-
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t{14}]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex"/>
4-
5-
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
6-
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
7-
8-
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
9-
<encoder>
10-
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
11-
</encoder>
12-
</appender>
13-
14-
<appender name="DEBUG_LEVEL_REMAPPER" class="org.springframework.boot.logging.logback.LevelRemappingAppender">
15-
<destinationLogger>org.springframework.boot</destinationLogger>
16-
</appender>
17-
18-
<root level="INFO">
19-
<appender-ref ref="CONSOLE" />
20-
</root>
21-
22-
<logger name="org.hibernate.validator.internal.util.Version" level="WARN"/>
23-
<logger name="org.apache.coyote.http11.Http11NioProtocol" level="WARN"/>
24-
<logger name="org.crsh.plugin" level="WARN"/>
25-
<logger name="org.apache.tomcat.util.net.NioSelectorPool" level="WARN"/>
26-
<logger name="org.apache.catalina.startup.DigesterFactory" level="ERROR"/>
27-
<logger name="org.thymeleaf" additivity="false">
28-
<appender-ref ref="DEBUG_LEVEL_REMAPPER"/>
29-
</logger>
30-
31-
</included>
2+
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/basic.xml" />
4+
</configuration>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<included>
3+
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t{14}]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex"/>
4+
5+
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
6+
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
7+
8+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
9+
<encoder>
10+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
11+
</encoder>
12+
</appender>
13+
14+
<appender name="DEBUG_LEVEL_REMAPPER" class="org.springframework.boot.logging.logback.LevelRemappingAppender">
15+
<destinationLogger>org.springframework.boot</destinationLogger>
16+
</appender>
17+
18+
<root level="INFO">
19+
<appender-ref ref="CONSOLE" />
20+
</root>
21+
22+
<logger name="org.hibernate.validator.internal.util.Version" level="WARN"/>
23+
<logger name="org.apache.coyote.http11.Http11NioProtocol" level="WARN"/>
24+
<logger name="org.crsh.plugin" level="WARN"/>
25+
<logger name="org.apache.tomcat.util.net.NioSelectorPool" level="WARN"/>
26+
<logger name="org.apache.catalina.startup.DigesterFactory" level="ERROR"/>
27+
<logger name="org.thymeleaf" additivity="false">
28+
<appender-ref ref="DEBUG_LEVEL_REMAPPER"/>
29+
</logger>
30+
31+
</included>

spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@
2424
import org.junit.Before;
2525
import org.junit.Rule;
2626
import org.junit.Test;
27+
import org.slf4j.ILoggerFactory;
28+
import org.slf4j.impl.StaticLoggerBinder;
2729
import org.springframework.boot.logging.LogLevel;
2830
import org.springframework.boot.test.OutputCapture;
2931
import org.springframework.util.StringUtils;
3032

33+
import ch.qos.logback.classic.Logger;
34+
import ch.qos.logback.classic.LoggerContext;
35+
3136
import static org.hamcrest.Matchers.equalTo;
3237
import static org.junit.Assert.assertFalse;
38+
import static org.junit.Assert.assertNotNull;
3339
import static org.junit.Assert.assertThat;
3440
import static org.junit.Assert.assertTrue;
3541

@@ -65,6 +71,15 @@ public void clear() {
6571
System.clearProperty("PID");
6672
}
6773

74+
@Test
75+
public void testBasicConfigLocation() throws Exception {
76+
this.loggingSystem.beforeInitialize();
77+
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
78+
LoggerContext context = (LoggerContext) factory;
79+
Logger root = context.getLogger(Logger.ROOT_LOGGER_NAME);
80+
assertNotNull(root.getAppender("CONSOLE"));
81+
}
82+
6883
@Test
6984
public void testNonDefaultConfigLocation() throws Exception {
7085
this.loggingSystem.beforeInitialize();

0 commit comments

Comments
 (0)