Skip to content

Commit

Permalink
Grails Boot: Improve print information of the running app status
Browse files Browse the repository at this point in the history
  • Loading branch information
rainboyan committed May 10, 2023
1 parent cedad3c commit 355db1e
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions grails-boot/src/main/groovy/grails/boot/Grails.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,13 @@ protected void printRunStatus(ConfigurableApplicationContext applicationContext)
(ConfigurableApplicationContext) applicationContext.getParent())
);
}
String applicationName = app.getConfig().getProperty("info.app.name", "");
String applicationVersion = app.getConfig().getProperty("info.app.version", "");
String contextPath = app.getConfig().getProperty("server.servlet.context-path", "");
String hostName = app.getConfig().getProperty("server.address", "localhost");
int port = 8080;
String serverAddress = app.getConfig().getProperty("server.address", "localhost");
int serverPort = Integer.parseInt(app.getConfig().getProperty("server.port", "8080"));
if (applicationContext instanceof WebServerApplicationContext) {
port = ((WebServerApplicationContext) applicationContext).getWebServer().getPort();
serverPort = ((WebServerApplicationContext) applicationContext).getWebServer().getPort();
}
String hostAddress = "localhost";
try {
Expand All @@ -444,27 +446,29 @@ protected void printRunStatus(ConfigurableApplicationContext applicationContext)
catch (UnknownHostException e) {
getApplicationLog().warn("The host name could not be determined, using `localhost` as fallback");
}
StringBuilder sb = new StringBuilder();
sb.append("%n----------------------------------------------------------------------------------------------");
sb.append("%n Application: %s");
sb.append("%n Version: %s");
sb.append("%n Environment: %s");
sb.append("%n Local: %s://%s:%s%s");
sb.append("%n External: %s://%s:%s%s");
sb.append("%n----------------------------------------------------------------------------------------------");
sb.append("%n");
getApplicationLog().info(String.format(sb.toString(),
app.getConfig().getProperty("info.app.name"),
app.getConfig().getProperty("info.app.version"),
Environment.getCurrent().getName(),
protocol,
hostName,
port,
contextPath,
protocol,
hostAddress,
port,
contextPath));
String sb =
"%n----------------------------------------------------------------------------------------------" +
"%n Application: %s" +
"%n Version: %s" +
"%n Environment: %s" +
"%n Local: %s://%s:%s%s" +
"%n External: %s://%s:%s%s" +
"%n----------------------------------------------------------------------------------------------" +
"%n";
getApplicationLog().info(
String.format(sb,
applicationName,
applicationVersion,
Environment.getCurrent().getName(),
protocol,
serverAddress,
serverPort,
contextPath,
protocol,
hostAddress,
serverPort,
contextPath)
);
}
catch (Exception ignored) {
}
Expand Down

0 comments on commit 355db1e

Please sign in to comment.