From 95e4da4fa2c8391ffa3533c9b49b74fd66cdd99c Mon Sep 17 00:00:00 2001 From: Matt Peterson Date: Wed, 26 Jun 2024 07:58:33 -0600 Subject: [PATCH] fix: adjusted error logging to log a throwable as a separate parameter Signed-off-by: Matt Peterson --- .../src/main/java/com/hedera/block/server/Server.java | 2 +- .../block/server/consumer/LiveStreamObserverImpl.java | 4 +--- .../block/server/mediator/LiveStreamMediatorImpl.java | 4 +++- .../persistence/storage/FileSystemBlockStorage.java | 11 +++++------ .../server/producer/ProducerBlockStreamObserver.java | 5 +++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/com/hedera/block/server/Server.java b/server/src/main/java/com/hedera/block/server/Server.java index ad7d4da2e..9519c0986 100644 --- a/server/src/main/java/com/hedera/block/server/Server.java +++ b/server/src/main/java/com/hedera/block/server/Server.java @@ -86,7 +86,7 @@ public static void main(final String[] args) { .start(); } catch (IOException e) { - LOGGER.log(System.Logger.Level.ERROR, "There was an exception starting the server: " + e.getMessage()); + LOGGER.log(System.Logger.Level.ERROR, "An exception was thrown starting the server", e); throw new RuntimeException(e); } } diff --git a/server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserverImpl.java b/server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserverImpl.java index 49b685b2e..4c94e2af0 100644 --- a/server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserverImpl.java +++ b/server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserverImpl.java @@ -23,7 +23,6 @@ /** * The LiveStreamObserverImpl class implements the LiveStreamObserver interface to pass blocks to the downstream consumer * via the notify method and manage the bidirectional stream to the consumer via the onNext, onError, and onCompleted methods. - * */ public class LiveStreamObserverImpl implements LiveStreamObserver { @@ -41,7 +40,6 @@ public class LiveStreamObserverImpl implements LiveStreamObserver blockPersistenceHandler) { this.blockPersistenceHandler = blockPersistenceHandler; @@ -86,6 +85,7 @@ public boolean isSubscribed(final LiveStreamObserver subscriber : subscribers) { subscriber.notify(block); diff --git a/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java b/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java index 83e29ecc1..821ea4e92 100644 --- a/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java +++ b/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java @@ -67,7 +67,7 @@ public FileSystemBlockStorage(final String key, final Config config) throws IOEx Files.createDirectory(blockNodeRootPath); LOGGER.log(System.Logger.Level.INFO, "Created block node root directory: " + blockNodeRootPath); } else { - LOGGER.log(System.Logger.Level.INFO, "Block node root directory exists: " + blockNodeRootPath); + LOGGER.log(System.Logger.Level.INFO, "Using existing block node root directory: " + blockNodeRootPath); } } @@ -84,12 +84,11 @@ public Optional write(final BlockStreamServiceGrpcProto.Block block) { try (FileOutputStream fos = new FileOutputStream(fullPath)) { block.writeTo(fos); - LOGGER.log(System.Logger.Level.DEBUG, "Wrote the block file: " + fullPath); + LOGGER.log(System.Logger.Level.DEBUG, "Successfully wrote the block file: " + fullPath); return Optional.of(id); - } - catch (IOException e) { - LOGGER.log(System.Logger.Level.ERROR, "Error writing the protobuf to file: " + e.getMessage()); + } catch (IOException e) { + LOGGER.log(System.Logger.Level.ERROR, "Error writing the protobuf to a file", e); return Optional.empty(); } } @@ -110,7 +109,7 @@ private Optional read(final String filePath) try (FileInputStream fis = new FileInputStream(filePath)) { return Optional.of(BlockStreamServiceGrpcProto.Block.parseFrom(fis)); } catch (FileNotFoundException io) { - LOGGER.log(System.Logger.Level.ERROR, "Error reading file: " + filePath); + LOGGER.log(System.Logger.Level.ERROR, "Error reading file: " + filePath, io); return Optional.empty(); } catch (IOException io) { throw new RuntimeException("Error reading file: " + filePath, io); diff --git a/server/src/main/java/com/hedera/block/server/producer/ProducerBlockStreamObserver.java b/server/src/main/java/com/hedera/block/server/producer/ProducerBlockStreamObserver.java index 62121f46a..9d07645eb 100644 --- a/server/src/main/java/com/hedera/block/server/producer/ProducerBlockStreamObserver.java +++ b/server/src/main/java/com/hedera/block/server/producer/ProducerBlockStreamObserver.java @@ -28,9 +28,10 @@ */ public class ProducerBlockStreamObserver implements StreamObserver { + private final System.Logger LOGGER = System.getLogger(getClass().getName()); + private final StreamMediator streamMediator; private final StreamObserver responseStreamObserver; - private final System.Logger LOGGER = System.getLogger(getClass().getName()); /** * Constructor for the ProducerBlockStreamObserver class. It is responsible for calling the mediator with blocks @@ -67,7 +68,7 @@ public void onNext(final BlockStreamServiceGrpcProto.Block block) { */ @Override public void onError(final Throwable t) { - LOGGER.log(System.Logger.Level.ERROR, "onError method called with the exception: " + t.getMessage()); + LOGGER.log(System.Logger.Level.ERROR, "onError method invoked with an exception", t); } /**