diff --git a/src/main/java/com/eactive/apim/portal/config/StartupInfoPrinter.java b/src/main/java/com/eactive/apim/portal/config/StartupInfoPrinter.java new file mode 100644 index 0000000..7a2bc65 --- /dev/null +++ b/src/main/java/com/eactive/apim/portal/config/StartupInfoPrinter.java @@ -0,0 +1,51 @@ +package com.eactive.apim.portal.config; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.boot.system.ApplicationPid; +import org.springframework.context.ApplicationListener; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +/** + * Prints a startup banner to stdout once boot is complete. + * + *

Uses {@link System#out} directly (not a logger) so the info is shown even when + * the logback console appender is disabled (CONSOLE_LOG_ENABLED=false). + */ +@Component +public class StartupInfoPrinter implements ApplicationListener { + + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { + Environment env = event.getApplicationContext().getEnvironment(); + + String port = env.getProperty("server.port", "8080"); + String contextPath = env.getProperty("server.servlet.context-path", "/"); + if (!contextPath.startsWith("/")) { + contextPath = "/" + contextPath; + } + String url = "http://localhost:" + port + contextPath; + + String[] active = env.getActiveProfiles(); + String profile = active.length == 0 + ? String.join(", ", env.getDefaultProfiles()) + : String.join(", ", active); + + String instanceName = env.getProperty("inst.Name", System.getProperty("inst.Name", "unknown")); + String pid = new ApplicationPid().toString(); + + StringBuilder sb = new StringBuilder(); + sb.append(System.lineSeparator()); + sb.append("=====================================================").append(System.lineSeparator()); + sb.append(" EAPIM Portal - startup complete").append(System.lineSeparator()); + sb.append("=====================================================").append(System.lineSeparator()); + sb.append(" URL : ").append(url).append(System.lineSeparator()); + sb.append(" Spring profile : ").append(profile).append(System.lineSeparator()); + sb.append(" Instance name : ").append(instanceName).append(System.lineSeparator()); + sb.append(" PID : ").append(pid).append(System.lineSeparator()); + sb.append("=====================================================").append(System.lineSeparator()); + + System.out.println(sb); + System.out.flush(); + } +}