12

In the Quarkus Application Configuration Guide it mentions how to configure an app with profiles (eg. %dev.quarkus.http.port=8181).

But is there a way to access a Profile (or Environment) API so I can log the active profiles ? For example something like Spring:

@ApplicationScoped
public class ApplicationLifeCycle {

    private static final Logger LOGGER = LoggerFactory.getLogger("ApplicationLifeCycle");

    @Inject Environment env;

    void onStart(@Observes StartupEvent ev) {
        LOGGER.info("The application is starting with profiles " + env.getActiveProfiles());
    }
agoncal
  • 464
  • 4
  • 14

2 Answers2

25

ProfileManager.getActiveProfile()?

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13
  • Was just about to write that :) – geoand Jun 18 '19 at 05:44
  • Best accept the answer @agoncal if the answer works for you to make it easy for future readers to know that it works without having to read through the comments – geoand Jun 18 '19 at 12:17
  • 1
    I can't understant why [quarkus docs](https://quarkus.io/guides/config#configuration-profiles) doesn't include a so simple explanation like that. Thank's a lot @Romain! – Mr. Anderson Mar 25 '21 at 02:05
  • 1
    Unfortunately, `ProfileManager.getActiveProfile()` is deprecated (as of 2.16.2.Final, & probably earlier), so we're back to square one again. =( – Mass Dot Net Feb 13 '23 at 19:43
9

The method ProfileManager.getActiveProfile() has been deprecated. You should use: ConfigUtils.getProfiles() instead.

Method:

public static List<String> getProfiles() {
     return ConfigProvider.getConfig().unwrap(SmallRyeConfig.class).getProfiles();
}

PD: Tested on Quarkus v2.16.1.Final

A.Casanova
  • 555
  • 4
  • 16