From 30a57e7d4f626d5e8b69892c128682e3dc76ca78 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Wed, 1 Sep 2021 11:43:18 -0700 Subject: [PATCH] core: minor formatting changes for bootstrap (#1102) --- .../com/netflix/zuul/sample/Bootstrap.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/zuul-sample/src/main/java/com/netflix/zuul/sample/Bootstrap.java b/zuul-sample/src/main/java/com/netflix/zuul/sample/Bootstrap.java index eaec2ec9e0..b1a9953201 100644 --- a/zuul-sample/src/main/java/com/netflix/zuul/sample/Bootstrap.java +++ b/zuul-sample/src/main/java/com/netflix/zuul/sample/Bootstrap.java @@ -20,6 +20,9 @@ import com.google.inject.Injector; import com.netflix.zuul.netty.server.BaseServerStartup; import com.netflix.zuul.netty.server.Server; +import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Bootstrap @@ -29,13 +32,15 @@ */ public class Bootstrap { + private static final Logger logger = LoggerFactory.getLogger(Bootstrap.class); + public static void main(String[] args) { new Bootstrap().start(); } public void start() { - System.out.println("Zuul Sample: starting up."); - long startTime = System.currentTimeMillis(); + long startNanos = System.nanoTime(); + logger.info("Zuul Sample: starting up."); int exitCode = 0; Server server = null; @@ -45,13 +50,13 @@ public void start() { BaseServerStartup serverStartup = injector.getInstance(BaseServerStartup.class); server = serverStartup.server(); - long startupDuration = System.currentTimeMillis() - startTime; - System.out.println("Zuul Sample: finished startup. Duration = " + startupDuration + " ms"); - server.start(); + long startupDuration = System.nanoTime() - startNanos; + logger.info( + "Zuul Sample: finished startup. Duration = {}ms", TimeUnit.NANOSECONDS.toMillis(startupDuration)); server.awaitTermination(); - } - catch (Throwable t) { + } catch (Throwable t) { + // Don't use logger here, as we may be shutting down the JVM and the logs won't be printed. t.printStackTrace(); System.err.println("###############"); System.err.println("Zuul Sample: initialization failed. Forcing shutdown now."); @@ -60,7 +65,9 @@ public void start() { } finally { // server shutdown - if (server != null) server.stop(); + if (server != null) { + server.stop(); + } System.exit(exitCode); }