Skip to content

Commit

Permalink
Improve logging on shutdown.
Browse files Browse the repository at this point in the history
If the JVM is already shutting down when the hook is scheduled, the message informing of
this is logged immediately, previously it could potentially be lost.
  • Loading branch information
Johan Torin committed Nov 16, 2023
1 parent db2f52c commit eafd577
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/org/opentripplanner/standalone/OtpStartupInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.List;
import java.util.stream.Collectors;
import org.opentripplanner.framework.application.ApplicationShutdownSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -37,14 +38,10 @@ public static void logInfo() {
// This is good when aggregating logs across multiple load balanced instances of OTP
// Hint: a regexp filter like "^OTP (START|SHUTTING)" will list nodes going up/down
LOG.info("OTP STARTING UP ({}) using Java {}", projectInfo().getVersionString(), javaVersion());
Runtime
.getRuntime()
.addShutdownHook(
new Thread(
() -> LOG.info("OTP SHUTTING DOWN ({})", projectInfo().getVersionString()),
"server-shutdown-info"
)
);
ApplicationShutdownSupport.addShutdownHook(
"server-shutdown-info",
() -> LOG.info("OTP SHUTTING DOWN ({})", projectInfo().getVersionString())
);
LOG.info(NEW_LINE + "{}", info());
}

Expand Down

0 comments on commit eafd577

Please sign in to comment.