Syntax improvement in the log output:
The standard logging output reports the active profile(s) used but the sentence is always in plural form (The following profiles are active
):
...
2022-01-10 17:07:48.046 INFO 14436 --- [ restartedMain] com.mycompany.myapp.TestApp : The following profiles are active: profile0
...
This is misleading when one profile is active but dangerous when more profiles are badly activated (read below).
Bad profile activation:
The comma is used as a separator in the environment variable parsing - i.e. running the application with:
-Dspring.profiles.active=profile0,profile1
However it is tempting to simply copy-paste profile0,profile1
in the active profile annotation and write:
@ActiveProfiles("profile0,profile1")
This (wrong) profile activation would make spring-boot activate a single profile (whose name contains a comma). The log output would still be expressed in plural form, misleading the developer to think two profiles are active.
Comment From: wilkinsona
Thanks for raising this, @gcoppex.
We could, in theory, have the same problem with multiple profiles:
@ActiveProfiles({"profile0,profile1", "profile2"})
Even with a distinction between a single profile and multiple profiles, we'd log The following profiles are active: profile0,profile1,profile2
and you'd be unable to tell that profile0,profile1
was one profile.
If we want to address this, I think it might be better to use ,
as the separator rather than just ,
and to include the number of profiles in the log message:
The following 1 profile is active: profile0
The following 2 profiles are active: profile0,profile1, profile2
The following 3 profiles are active: profile0, profile1, profile2
I'll flag this for a team meeting as I'd like to discuss the timing of the change and exactly what we want the new format to be.
Comment From: philwebb
We're going add the count and quote the profile strings. E.g.:
The following 2 profiles are active: "profile0,profile1", "profile2"
Comment From: gcoppex
Excellent, thanks.
Comment From: philwebb
This is an excellent first-timers-only
issue so I've opened #29891 with a more detailed description. Thanks @gcoppex, please subscribe to the new issue for updates.