Clarify log message with a profile containing a comma
See gh-29896
This commit is contained in:
@@ -667,13 +667,19 @@ public class SpringApplication {
|
|||||||
Log log = getApplicationLog();
|
Log log = getApplicationLog();
|
||||||
if (log.isInfoEnabled()) {
|
if (log.isInfoEnabled()) {
|
||||||
String[] activeProfiles = context.getEnvironment().getActiveProfiles();
|
String[] activeProfiles = context.getEnvironment().getActiveProfiles();
|
||||||
|
for (int i = 0; i < activeProfiles.length; i++) {
|
||||||
|
activeProfiles[i] = "\"" + activeProfiles[i] + "\"";
|
||||||
|
}
|
||||||
if (ObjectUtils.isEmpty(activeProfiles)) {
|
if (ObjectUtils.isEmpty(activeProfiles)) {
|
||||||
String[] defaultProfiles = context.getEnvironment().getDefaultProfiles();
|
String[] defaultProfiles = context.getEnvironment().getDefaultProfiles();
|
||||||
log.info("No active profile set, falling back to default profiles: "
|
for (int i = 0; i < defaultProfiles.length; i++) {
|
||||||
|
defaultProfiles[i] = "\"" + defaultProfiles[i] + "\"";
|
||||||
|
}
|
||||||
|
log.info("No active profile set, falling back to " + defaultProfiles.length + " default profile(s): "
|
||||||
+ StringUtils.arrayToCommaDelimitedString(defaultProfiles));
|
+ StringUtils.arrayToCommaDelimitedString(defaultProfiles));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.info("The following profiles are active: "
|
log.info("The following " + activeProfiles.length + " profile(s) are active: "
|
||||||
+ StringUtils.arrayToCommaDelimitedString(activeProfiles));
|
+ StringUtils.arrayToCommaDelimitedString(activeProfiles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ class SpringApplicationTests {
|
|||||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
application.setWebApplicationType(WebApplicationType.NONE);
|
||||||
this.context = application.run();
|
this.context = application.run();
|
||||||
assertThat(output).contains("No active profile set, falling back to default profiles: default");
|
assertThat(output).contains("No active profile set, falling back to 1 default profile(s): \"default\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -261,7 +261,7 @@ class SpringApplicationTests {
|
|||||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
application.setWebApplicationType(WebApplicationType.NONE);
|
||||||
this.context = application.run("--spring.profiles.active=myprofiles");
|
this.context = application.run("--spring.profiles.active=myprofiles");
|
||||||
assertThat(output).contains("The following profiles are active: myprofile");
|
assertThat(output).contains("The following 1 profile(s) are active: \"myprofiles\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -273,6 +273,15 @@ class SpringApplicationTests {
|
|||||||
assertThat(output).contains("o.s.b.SpringApplication");
|
assertThat(output).contains("o.s.b.SpringApplication");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void logsMultipleActiveProfilesWithComma(CapturedOutput output) {
|
||||||
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||||
|
application.setWebApplicationType(WebApplicationType.NONE);
|
||||||
|
application.setAdditionalProfiles("p1,p2", "p3");
|
||||||
|
application.run();
|
||||||
|
assertThat(output).contains("The following 2 profile(s) are active: \"p1,p2\",\"p3\"");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setIgnoreBeanInfoPropertyByDefault(CapturedOutput output) {
|
void setIgnoreBeanInfoPropertyByDefault(CapturedOutput output) {
|
||||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user