From 6ec53fc9036876fc0fe007f1996c3323e836ba68 Mon Sep 17 00:00:00 2001 From: Gary Clayburg Date: Mon, 28 Jun 2021 17:50:17 -0500 Subject: [PATCH] fix #6 debug settings were not honored by upbanner --- .../garyclayburg/upbanner/DebugDumper.java | 5 +- .../garyclayburg/upbanner/WhatsUpProbes.java | 64 ++++++++----------- .../garyclayburg/upbanner/WhatsUpTest.java | 13 +--- .../demo/WebJar1519ApplicationTests.java | 5 ++ .../main/java/com/example/demo/MyWhatsUp.java | 8 --- 5 files changed, 40 insertions(+), 55 deletions(-) diff --git a/upbanner-core/src/main/java/com/garyclayburg/upbanner/DebugDumper.java b/upbanner-core/src/main/java/com/garyclayburg/upbanner/DebugDumper.java index 03ecfad..48dc498 100644 --- a/upbanner-core/src/main/java/com/garyclayburg/upbanner/DebugDumper.java +++ b/upbanner-core/src/main/java/com/garyclayburg/upbanner/DebugDumper.java @@ -77,7 +77,10 @@ public WhatsUpProbes getWhatsUpProbes() { } public void dumpAll() { - whatsUpProbes.dumpAll(); + if (environment.getProperty("upbanner.debug") != null && + environment.getProperty("upbanner.debug").equalsIgnoreCase("true")) { + whatsUpProbes.dumpAll(); + } } private UpbannerSettings createUpbannerSettings() { diff --git a/upbanner-core/src/main/java/com/garyclayburg/upbanner/WhatsUpProbes.java b/upbanner-core/src/main/java/com/garyclayburg/upbanner/WhatsUpProbes.java index 2fffbe0..729a3b1 100644 --- a/upbanner-core/src/main/java/com/garyclayburg/upbanner/WhatsUpProbes.java +++ b/upbanner-core/src/main/java/com/garyclayburg/upbanner/WhatsUpProbes.java @@ -308,44 +308,36 @@ public String getEnvironmentProperty(String key) { * We attempt to print this information as soon as possible during application startup */ public void dumpAll() { - dumpAll(stringBuilder -> { - }); - } - - public void dumpAll(ExtraLinePrinter extraLinePrinter) { - if (upbannerSettings.isDebug()) { - StringBuilder probe; - if (this.probeResult == null || upbannerSettings.isForceRecompute()) { - probe = new StringBuilder(); - section(probe, "\n===== What OS and hardware are we running on ====="); - oshiProbe.createReport(probe); - section(probe, "\n===== What OS resources are limited =============="); - dumpCPUlimits(probe); - dumpMemoryLimits(probe); - section(probe, "\n===== What environment are we running with ======="); + StringBuilder probe; + if (this.probeResult == null || upbannerSettings.isForceRecompute()) { + probe = new StringBuilder(); + section(probe, "\n===== What OS and hardware are we running on ====="); + oshiProbe.createReport(probe); + section(probe, "\n===== What OS resources are limited =============="); + dumpCPUlimits(probe); + dumpMemoryLimits(probe); + section(probe, "\n===== What environment are we running with ======="); // dumpSystemProperties(probe); // dumpENV(probe); - dumpPropertySources(probe); - section(probe, "\n===== How was it built ==========================="); - dumpBuildProperties(probe); - section(probe, "\n===== How was it started ========================="); - jarProbe.init(probe); - dumpStartupCommandJVMargs(probe); - section(probe, "\n===== What is running ============================"); - dumpGitProperties(probe); - jarProbe.createRootManifestReport(probe); - jarProbe.createSnapshotJarReport(probe); - extraLinePrinter.call(probe); - this.probeResult = probe; - } else { - probe = this.probeResult; - } - if (log.isInfoEnabled()) { - log.info("Environment probe:" + System.lineSeparator() + probe); - } else { // the operator wants to show the information. Lets not also force them to enable INFO - log.warn("INFO logging is disabled. showing requested debug info as WARN instead"); - log.warn("Environment probe:" + System.lineSeparator() + probe); - } + dumpPropertySources(probe); + section(probe, "\n===== How was it built ==========================="); + dumpBuildProperties(probe); + section(probe, "\n===== How was it started ========================="); + jarProbe.init(probe); + dumpStartupCommandJVMargs(probe); + section(probe, "\n===== What is running ============================"); + dumpGitProperties(probe); + jarProbe.createRootManifestReport(probe); + jarProbe.createSnapshotJarReport(probe); + this.probeResult = probe; + } else { + probe = this.probeResult; + } + if (log.isInfoEnabled()) { + log.info("Environment probe:" + System.lineSeparator() + probe); + } else { // the operator wants to show the information. Lets not also force them to enable INFO + log.warn("INFO logging is disabled. showing requested debug info as WARN instead"); + log.warn("Environment probe:" + System.lineSeparator() + probe); } } diff --git a/upbanner-core/src/test/java/com/garyclayburg/upbanner/WhatsUpTest.java b/upbanner-core/src/test/java/com/garyclayburg/upbanner/WhatsUpTest.java index 58f402d..01d5c83 100644 --- a/upbanner-core/src/test/java/com/garyclayburg/upbanner/WhatsUpTest.java +++ b/upbanner-core/src/test/java/com/garyclayburg/upbanner/WhatsUpTest.java @@ -41,7 +41,9 @@ public void dumpOShi() { UpbannerSettings upbannerSettings = new UpbannerSettings(); upbannerSettings.setDebug(true); FullOshiProbe fullOshiProbe = new FullOshiProbe(); - fullOshiProbe.createReport(new StringBuilder()); + StringBuilder probeOut = new StringBuilder(); + fullOshiProbe.createReport(probeOut); + log.info("osh probe: " + probeOut); } @Test @@ -55,15 +57,6 @@ public void dumpBuildProps() { log.info(probeOut.toString()); } - @Test - public void dumpAll() { - Properties p = new Properties(); - p.setProperty("time", "2020-12-08T00:52:19Z"); - BuildProperties buildProperties = new BuildProperties(p); - WhatsUpProbes whatsUpProbes = new WhatsUpProbes(null,buildProperties,new FullOshiProbe(),new FileJarDumper(),new UpbannerSettings(), null); - whatsUpProbes.dumpAll(); - } - @Test public void showName() { Properties p = new Properties(); diff --git a/webjar1519/src/test/java/com/example/demo/WebJar1519ApplicationTests.java b/webjar1519/src/test/java/com/example/demo/WebJar1519ApplicationTests.java index 5caa19c..a002fa0 100644 --- a/webjar1519/src/test/java/com/example/demo/WebJar1519ApplicationTests.java +++ b/webjar1519/src/test/java/com/example/demo/WebJar1519ApplicationTests.java @@ -57,4 +57,9 @@ public void setUp() { public void upbannerApplicationIsUP() { assertTrue(outContent.toString().contains("WebJar1519ApplicationTests is UP!")); } + + @Test + public void upbannerDebugIsOff() { + assertFalse(outContent.toString().contains("Environment probe:")); + } } diff --git a/webjaroverride/src/main/java/com/example/demo/MyWhatsUp.java b/webjaroverride/src/main/java/com/example/demo/MyWhatsUp.java index 92957f4..852947a 100644 --- a/webjaroverride/src/main/java/com/example/demo/MyWhatsUp.java +++ b/webjaroverride/src/main/java/com/example/demo/MyWhatsUp.java @@ -32,14 +32,6 @@ public MyWhatsUp(WhatsUpProbes whatsUpProbes, Environment environment) { this.environment = environment; } - @PostConstruct - public void printDebugOnStartup() { - whatsUpProbes.dumpAll(stringBuilder -> stringBuilder - .append(" working directory: ") - .append(whatsUpProbes.getEnvironmentPropertyPrintable("PWD")) - .append(System.lineSeparator())); - } - @Override public void printBanner() { //compact banner