Skip to content

Commit 95e4da4

Browse files
fix: adjusted error logging to log a throwable as a separate parameter
Signed-off-by: Matt Peterson <[email protected]>
1 parent 34d6acc commit 95e4da4

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

server/src/main/java/com/hedera/block/server/Server.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static void main(final String[] args) {
8686
.start();
8787

8888
} catch (IOException e) {
89-
LOGGER.log(System.Logger.Level.ERROR, "There was an exception starting the server: " + e.getMessage());
89+
LOGGER.log(System.Logger.Level.ERROR, "An exception was thrown starting the server", e);
9090
throw new RuntimeException(e);
9191
}
9292
}

server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserverImpl.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
/**
2424
* The LiveStreamObserverImpl class implements the LiveStreamObserver interface to pass blocks to the downstream consumer
2525
* via the notify method and manage the bidirectional stream to the consumer via the onNext, onError, and onCompleted methods.
26-
*
2726
*/
2827
public class LiveStreamObserverImpl implements LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> {
2928

@@ -41,7 +40,6 @@ public class LiveStreamObserverImpl implements LiveStreamObserver<BlockStreamSer
4140
*
4241
* @param mediator the mediator
4342
* @param responseStreamObserver the response stream observer
44-
*
4543
*/
4644
public LiveStreamObserverImpl(
4745
final long timeoutThresholdMillis,
@@ -102,7 +100,7 @@ public void onNext(final BlockStreamServiceGrpcProto.BlockResponse blockResponse
102100
*/
103101
@Override
104102
public void onError(final Throwable t) {
105-
LOGGER.log(System.Logger.Level.ERROR, t.getMessage());
103+
LOGGER.log(System.Logger.Level.ERROR, t);
106104
mediator.unsubscribe(this);
107105
}
108106

server/src/main/java/com/hedera/block/server/mediator/LiveStreamMediatorImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class LiveStreamMediatorImpl implements StreamMediator<BlockStreamService
4040
* Constructor for the LiveStreamMediatorImpl class.
4141
*
4242
* @param blockPersistenceHandler the block persistence handler
43-
*
4443
*/
4544
public LiveStreamMediatorImpl(final BlockPersistenceHandler<BlockStreamServiceGrpcProto.Block> blockPersistenceHandler) {
4645
this.blockPersistenceHandler = blockPersistenceHandler;
@@ -86,6 +85,7 @@ public boolean isSubscribed(final LiveStreamObserver<BlockStreamServiceGrpcProto
8685
*/
8786
@Override
8887
public void unsubscribeAll() {
88+
LOGGER.log(System.Logger.Level.DEBUG, "Unsubscribing all observers from the mediator");
8989
subscribers.clear();
9090
}
9191

@@ -97,6 +97,8 @@ public void unsubscribeAll() {
9797
@Override
9898
public void notifyAll(final BlockStreamServiceGrpcProto.Block block) {
9999

100+
LOGGER.log(System.Logger.Level.DEBUG, "Notifying " + subscribers.size() + " observers of a new block");
101+
100102
// Proxy the block to all live stream subscribers
101103
for (final LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> subscriber : subscribers) {
102104
subscriber.notify(block);

server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public FileSystemBlockStorage(final String key, final Config config) throws IOEx
6767
Files.createDirectory(blockNodeRootPath);
6868
LOGGER.log(System.Logger.Level.INFO, "Created block node root directory: " + blockNodeRootPath);
6969
} else {
70-
LOGGER.log(System.Logger.Level.INFO, "Block node root directory exists: " + blockNodeRootPath);
70+
LOGGER.log(System.Logger.Level.INFO, "Using existing block node root directory: " + blockNodeRootPath);
7171
}
7272
}
7373

@@ -84,12 +84,11 @@ public Optional<Long> write(final BlockStreamServiceGrpcProto.Block block) {
8484

8585
try (FileOutputStream fos = new FileOutputStream(fullPath)) {
8686
block.writeTo(fos);
87-
LOGGER.log(System.Logger.Level.DEBUG, "Wrote the block file: " + fullPath);
87+
LOGGER.log(System.Logger.Level.DEBUG, "Successfully wrote the block file: " + fullPath);
8888

8989
return Optional.of(id);
90-
}
91-
catch (IOException e) {
92-
LOGGER.log(System.Logger.Level.ERROR, "Error writing the protobuf to file: " + e.getMessage());
90+
} catch (IOException e) {
91+
LOGGER.log(System.Logger.Level.ERROR, "Error writing the protobuf to a file", e);
9392
return Optional.empty();
9493
}
9594
}
@@ -110,7 +109,7 @@ private Optional<BlockStreamServiceGrpcProto.Block> read(final String filePath)
110109
try (FileInputStream fis = new FileInputStream(filePath)) {
111110
return Optional.of(BlockStreamServiceGrpcProto.Block.parseFrom(fis));
112111
} catch (FileNotFoundException io) {
113-
LOGGER.log(System.Logger.Level.ERROR, "Error reading file: " + filePath);
112+
LOGGER.log(System.Logger.Level.ERROR, "Error reading file: " + filePath, io);
114113
return Optional.empty();
115114
} catch (IOException io) {
116115
throw new RuntimeException("Error reading file: " + filePath, io);

server/src/main/java/com/hedera/block/server/producer/ProducerBlockStreamObserver.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
*/
2929
public class ProducerBlockStreamObserver implements StreamObserver<BlockStreamServiceGrpcProto.Block> {
3030

31+
private final System.Logger LOGGER = System.getLogger(getClass().getName());
32+
3133
private final StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamMediator;
3234
private final StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> responseStreamObserver;
33-
private final System.Logger LOGGER = System.getLogger(getClass().getName());
3435

3536
/**
3637
* 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) {
6768
*/
6869
@Override
6970
public void onError(final Throwable t) {
70-
LOGGER.log(System.Logger.Level.ERROR, "onError method called with the exception: " + t.getMessage());
71+
LOGGER.log(System.Logger.Level.ERROR, "onError method invoked with an exception", t);
7172
}
7273

7374
/**

0 commit comments

Comments
 (0)