Skip to content

Commit

Permalink
fix: adjusted error logging to log a throwable as a separate parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Jun 26, 2024
1 parent 34d6acc commit 95e4da4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/com/hedera/block/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> {

Expand All @@ -41,7 +40,6 @@ public class LiveStreamObserverImpl implements LiveStreamObserver<BlockStreamSer
*
* @param mediator the mediator
* @param responseStreamObserver the response stream observer
*
*/
public LiveStreamObserverImpl(
final long timeoutThresholdMillis,
Expand Down Expand Up @@ -102,7 +100,7 @@ public void onNext(final BlockStreamServiceGrpcProto.BlockResponse blockResponse
*/
@Override
public void onError(final Throwable t) {
LOGGER.log(System.Logger.Level.ERROR, t.getMessage());
LOGGER.log(System.Logger.Level.ERROR, t);
mediator.unsubscribe(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class LiveStreamMediatorImpl implements StreamMediator<BlockStreamService
* Constructor for the LiveStreamMediatorImpl class.
*
* @param blockPersistenceHandler the block persistence handler
*
*/
public LiveStreamMediatorImpl(final BlockPersistenceHandler<BlockStreamServiceGrpcProto.Block> blockPersistenceHandler) {
this.blockPersistenceHandler = blockPersistenceHandler;
Expand Down Expand Up @@ -86,6 +85,7 @@ public boolean isSubscribed(final LiveStreamObserver<BlockStreamServiceGrpcProto
*/
@Override
public void unsubscribeAll() {
LOGGER.log(System.Logger.Level.DEBUG, "Unsubscribing all observers from the mediator");
subscribers.clear();
}

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

LOGGER.log(System.Logger.Level.DEBUG, "Notifying " + subscribers.size() + " observers of a new block");

// Proxy the block to all live stream subscribers
for (final LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> subscriber : subscribers) {
subscriber.notify(block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -84,12 +84,11 @@ public Optional<Long> 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();
}
}
Expand All @@ -110,7 +109,7 @@ private Optional<BlockStreamServiceGrpcProto.Block> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
*/
public class ProducerBlockStreamObserver implements StreamObserver<BlockStreamServiceGrpcProto.Block> {

private final System.Logger LOGGER = System.getLogger(getClass().getName());

private final StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamMediator;
private final StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> responseStreamObserver;
private final System.Logger LOGGER = System.getLogger(getClass().getName());

/**
* Constructor for the ProducerBlockStreamObserver class. It is responsible for calling the mediator with blocks
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 95e4da4

Please sign in to comment.