Skip to content

Commit

Permalink
Merge pull request #4302 from gastaldi/show_name_and_version
Browse files Browse the repository at this point in the history
Support customization of the project name and version in logs
  • Loading branch information
stuartwdouglas authored Oct 2, 2019
2 parents 7a44f08 + f63bd73 commit 5b11729
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public final class ApplicationInfoBuildItem extends SimpleBuildItem {

public static final String UNSET_VALUE = "<<unset>>";
private static final String UNSET_VALUE = "<<unset>>";

private final String name;
private final String version;
Expand All @@ -15,10 +15,10 @@ public ApplicationInfoBuildItem(String name, String version) {
}

public String getName() {
return name;
return name == null ? UNSET_VALUE : name;
}

public String getVersion() {
return version;
return version == null ? UNSET_VALUE : version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationClassNameBuildItem;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.deployment.builditem.BytecodeRecorderObjectLoaderBuildItem;
import io.quarkus.deployment.builditem.ClassOutputBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
Expand Down Expand Up @@ -66,7 +67,8 @@ MainClassBuildItem build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
BuildProducer<ApplicationClassNameBuildItem> appClassNameProducer,
List<BytecodeRecorderObjectLoaderBuildItem> loaders,
ClassOutputBuildItem classOutput,
LaunchModeBuildItem launchMode) {
LaunchModeBuildItem launchMode,
ApplicationInfoBuildItem applicationInfo) {

String appClassName = APP_CLASS + COUNT.incrementAndGet();
appClassNameProducer.produce(new ApplicationClassNameBuildItem(appClassName));
Expand Down Expand Up @@ -197,7 +199,10 @@ MainClassBuildItem build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
.sorted()
.collect(Collectors.joining(", ")));
tryBlock.invokeStaticMethod(
ofMethod(Timing.class, "printStartupTime", void.class, String.class, String.class, String.class, boolean.class),
ofMethod(Timing.class, "printStartupTime", void.class, String.class, String.class, String.class, String.class,
String.class, boolean.class),
tryBlock.load(applicationInfo.getName()),
tryBlock.load(applicationInfo.getVersion()),
tryBlock.load(Version.getVersion()),
featuresHandle,
tryBlock.load(ProfileManager.getActiveProfile()),
Expand Down
14 changes: 12 additions & 2 deletions core/runtime/src/main/java/io/quarkus/runtime/Timing.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Timing {

private static volatile String httpServerInfo = "";

private static final String UNSET_VALUE = "<<unset>>";

public static void staticInitStarted() {
if (bootStartTime < 0) {
bootStartTime = System.nanoTime();
Expand Down Expand Up @@ -50,12 +52,20 @@ public static void restart() {
bootStartTime = System.nanoTime();
}

public static void printStartupTime(String version, String features, String profile, boolean liveCoding) {
public static void printStartupTime(String name, String version, String quarkusVersion, String features, String profile,
boolean liveCoding) {
final long bootTimeNanoSeconds = System.nanoTime() - bootStartTime;
final Logger logger = Logger.getLogger("io.quarkus");
//Use a BigDecimal so we can render in seconds with 3 digits precision, as requested:
final BigDecimal secondsRepresentation = convertToBigDecimalSeconds(bootTimeNanoSeconds);
logger.infof("Quarkus %s started in %ss. %s", version, secondsRepresentation, httpServerInfo);
String safeAppName = (name == null || name.isEmpty()) ? UNSET_VALUE : name;
String safeAppVersion = (version == null || version.isEmpty()) ? UNSET_VALUE : version;
if (UNSET_VALUE.equals(safeAppName) || UNSET_VALUE.equals(safeAppVersion)) {
logger.infof("Quarkus %s started in %ss. %s", quarkusVersion, secondsRepresentation, httpServerInfo);
} else {
logger.infof("%s %s (running on Quarkus %s) started in %ss. %s", name, version, quarkusVersion,
secondsRepresentation, httpServerInfo);
}
logger.infof("Profile %s activated. %s", profile, liveCoding ? "Live Coding activated." : "");
logger.infof("Installed features: [%s]", features);
bootStartTime = -1;
Expand Down

0 comments on commit 5b11729

Please sign in to comment.