diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializer.java index 255eaf87dd..79bdda7a83 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializer.java @@ -114,7 +114,8 @@ public class AutoConfigurationReportLoggingInitializer implements .getBeanFactory()); } if (this.report.getConditionAndOutcomesBySource().size() > 0) { - if (isCrashReport && this.logger.isInfoEnabled()) { + if (isCrashReport && this.logger.isInfoEnabled() + && !this.logger.isDebugEnabled()) { this.logger.info("\n\nError starting ApplicationContext. " + "To display the auto-configuration report enabled " + "debug logging (start with --debug)\n\n"); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializerTests.java index 44b31de77b..f268bad3dd 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReportLoggingInitializerTests.java @@ -71,11 +71,14 @@ public class AutoConfigurationReportLoggingInitializerTests { @Before public void setup() { + setupLogging(true, true); + } + private void setupLogging(boolean debug, boolean info) { this.log = mock(Log.class); logThreadLocal.set(this.log); - given(this.log.isDebugEnabled()).willReturn(true); + given(this.log.isDebugEnabled()).willReturn(debug); willAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { @@ -84,7 +87,7 @@ public class AutoConfigurationReportLoggingInitializerTests { } }).given(this.log).debug(anyObject()); - given(this.log.isInfoEnabled()).willReturn(true); + given(this.log.isInfoEnabled()).willReturn(info); willAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { @@ -115,7 +118,7 @@ public class AutoConfigurationReportLoggingInitializerTests { } @Test - public void logsInfoAndDebugOnError() { + public void logsDebugOnError() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); this.initializer.initialize(context); context.register(ErrorConfig.class); @@ -129,6 +132,25 @@ public class AutoConfigurationReportLoggingInitializerTests { } assertThat(this.debugLog.size(), not(equalTo(0))); + assertThat(this.infoLog.size(), equalTo(0)); + } + + @Test + public void logsInfoOnErrorIfDebugDisabled() { + setupLogging(false, true); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + this.initializer.initialize(context); + context.register(ErrorConfig.class); + try { + context.refresh(); + fail("Did not error"); + } + catch (Exception ex) { + this.initializer.onApplicationEvent(new SpringApplicationErrorEvent( + new SpringApplication(), context, new String[] {}, ex)); + } + + assertThat(this.debugLog.size(), equalTo(0)); assertThat(this.infoLog.size(), not(equalTo(0))); }