Skip to content

Commit c8466a1

Browse files
gcoppexsnicoll
authored andcommitted
Clarify log message with a profile containing a comma
See gh-29896
1 parent 5baa71f commit c8466a1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,19 @@ protected void logStartupProfileInfo(ConfigurableApplicationContext context) {
667667
Log log = getApplicationLog();
668668
if (log.isInfoEnabled()) {
669669
String[] activeProfiles = context.getEnvironment().getActiveProfiles();
670+
for (int i = 0; i < activeProfiles.length; i++) {
671+
activeProfiles[i] = "\"" + activeProfiles[i] + "\"";
672+
}
670673
if (ObjectUtils.isEmpty(activeProfiles)) {
671674
String[] defaultProfiles = context.getEnvironment().getDefaultProfiles();
672-
log.info("No active profile set, falling back to default profiles: "
675+
for (int i = 0; i < defaultProfiles.length; i++) {
676+
defaultProfiles[i] = "\"" + defaultProfiles[i] + "\"";
677+
}
678+
log.info("No active profile set, falling back to " + defaultProfiles.length + " default profile(s): "
673679
+ StringUtils.arrayToCommaDelimitedString(defaultProfiles));
674680
}
675681
else {
676-
log.info("The following profiles are active: "
682+
log.info("The following " + activeProfiles.length + " profile(s) are active: "
677683
+ StringUtils.arrayToCommaDelimitedString(activeProfiles));
678684
}
679685
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ void logsNoActiveProfiles(CapturedOutput output) {
253253
SpringApplication application = new SpringApplication(ExampleConfig.class);
254254
application.setWebApplicationType(WebApplicationType.NONE);
255255
this.context = application.run();
256-
assertThat(output).contains("No active profile set, falling back to default profiles: default");
256+
assertThat(output).contains("No active profile set, falling back to 1 default profile(s): \"default\"");
257257
}
258258

259259
@Test
260260
void logsActiveProfiles(CapturedOutput output) {
261261
SpringApplication application = new SpringApplication(ExampleConfig.class);
262262
application.setWebApplicationType(WebApplicationType.NONE);
263263
this.context = application.run("--spring.profiles.active=myprofiles");
264-
assertThat(output).contains("The following profiles are active: myprofile");
264+
assertThat(output).contains("The following 1 profile(s) are active: \"myprofiles\"");
265265
}
266266

267267
@Test
@@ -273,6 +273,15 @@ void enableBannerInLogViaProperty(CapturedOutput output) {
273273
assertThat(output).contains("o.s.b.SpringApplication");
274274
}
275275

276+
@Test
277+
void logsMultipleActiveProfilesWithComma(CapturedOutput output) {
278+
SpringApplication application = new SpringApplication(ExampleConfig.class);
279+
application.setWebApplicationType(WebApplicationType.NONE);
280+
application.setAdditionalProfiles("p1,p2", "p3");
281+
application.run();
282+
assertThat(output).contains("The following 2 profile(s) are active: \"p1,p2\",\"p3\"");
283+
}
284+
276285
@Test
277286
void setIgnoreBeanInfoPropertyByDefault(CapturedOutput output) {
278287
SpringApplication application = new SpringApplication(ExampleConfig.class);

0 commit comments

Comments
 (0)