From 73af5b23dd2aea45ffc630e843083b29dc1ef81d Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Thu, 5 Dec 2024 17:52:28 +0200 Subject: [PATCH] refine error handling Signed-off-by: georgi-l95 --- .../block/simulator/BlockStreamSimulatorApp.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorApp.java b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorApp.java index 7a1ae31a..7cdb2205 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorApp.java +++ b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorApp.java @@ -37,7 +37,10 @@ import java.io.IOException; import java.io.InputStream; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; import java.util.logging.LogManager; +import java.util.logging.Logger; import javax.inject.Inject; /** BlockStream Simulator App */ @@ -136,9 +139,18 @@ public StreamStatus getStreamStatus() { } private void loadLoggingProperties() { + final LogManager logManager = LogManager.getLogManager(); try (InputStream is = BlockStreamSimulator.class.getClassLoader().getResourceAsStream(LOGGING_PROPERTIES)) { - LogManager.getLogManager().readConfiguration(is); - } catch (IOException e) { + logManager.readConfiguration(is); + } catch (IOException | NullPointerException e) { + logManager.reset(); + Logger rootLogger = logManager.getLogger(""); + ConsoleHandler consoleHandler = new ConsoleHandler(); + + consoleHandler.setLevel(Level.INFO); + rootLogger.setLevel(Level.INFO); + rootLogger.addHandler(consoleHandler); + LOGGER.log( ERROR, "Loading Logging Configuration failed, continuing with default. Error is: %s"