Skip to content

Commit c499511

Browse files
committed
Update simpler log info on file creation
1 parent b2a3696 commit c499511

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

Diff for: ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/DebugDataDumper.java

+21-8
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,29 @@ public void saveGossipMessageDecodingError(
6262
if (!enabled) {
6363
return;
6464
}
65-
final String fileName = String.format("%s.ssz", formatTimestamp(arrivalTimestamp));
65+
final String formattedTimestamp = formatTimestamp(arrivalTimestamp);
66+
final String fileName = String.format("%s.ssz", formattedTimestamp);
6667
final Path topicPath =
6768
Path.of(GOSSIP_MESSAGES_DIR).resolve(DECODING_ERROR_SUB_DIR).resolve(topic);
69+
final String identifiers = String.format("on topic %s at %s", topic, formattedTimestamp);
6870
saveBytesToFile(
69-
"gossip message with decoding error", topicPath.resolve(fileName), originalMessage);
71+
"gossip message with decoding error",
72+
identifiers,
73+
topicPath.resolve(fileName),
74+
originalMessage);
7075
}
7176

7277
public void saveGossipRejectedMessageToFile(
7378
final String topic, final Optional<UInt64> arrivalTimestamp, final Bytes decodedMessage) {
7479
if (!enabled) {
7580
return;
7681
}
77-
final String fileName = String.format("%s.ssz", formatTimestamp(arrivalTimestamp));
82+
final String formattedTimestamp = formatTimestamp(arrivalTimestamp);
83+
final String fileName = String.format("%s.ssz", formattedTimestamp);
7884
final Path topicPath = Path.of(GOSSIP_MESSAGES_DIR).resolve(REJECTED_SUB_DIR).resolve(topic);
79-
saveBytesToFile("rejected gossip message", topicPath.resolve(fileName), decodedMessage);
85+
final String identifiers = String.format("on topic %s at %s", topic, formattedTimestamp);
86+
saveBytesToFile(
87+
"rejected gossip message", identifiers, topicPath.resolve(fileName), decodedMessage);
8088
}
8189

8290
public void saveInvalidBlockToFile(
@@ -85,16 +93,21 @@ public void saveInvalidBlockToFile(
8593
return;
8694
}
8795
final String fileName = String.format("%s_%s.ssz", slot, blockRoot.toUnprefixedHexString());
88-
saveBytesToFile("invalid block", Path.of(INVALID_BLOCK_DIR).resolve(fileName), blockSsz);
96+
final String identifiers = String.format("at slot %s(%s)", slot, blockRoot);
97+
saveBytesToFile(
98+
"invalid block", identifiers, Path.of(INVALID_BLOCK_DIR).resolve(fileName), blockSsz);
8999
}
90100

91101
@VisibleForTesting
92102
protected void saveBytesToFile(
93-
final String description, final Path relativeFilePath, final Bytes bytes) {
103+
final String description,
104+
final String identifiers,
105+
final Path relativeFilePath,
106+
final Bytes bytes) {
94107
final Path path = directory.resolve(relativeFilePath);
95108
try {
96109
Files.write(path, bytes.toArray());
97-
LOG.info("Saved {} bytes to file. Location: {}", description, relativeFilePath);
110+
LOG.info("Saved {} {}", description, identifiers);
98111
} catch (NoSuchFileException e) {
99112
if (!path.getParent().toFile().mkdirs()) {
100113
LOG.error("Failed to save {} bytes to file.", description, e);
@@ -111,7 +124,7 @@ private void saveAfterCreatingTopicDirectory(
111124
final Path path = directory.resolve(relativeFilePath);
112125
try {
113126
Files.write(path, bytes.toArray());
114-
LOG.info("Saved {} bytes to file. Location: {}", description, relativeFilePath);
127+
LOG.info("Saved {} ", description);
115128
} catch (IOException e) {
116129
LOG.error("Failed to save {} bytes to file.", description, e);
117130
if (!path.getParent().toFile().exists()) {

Diff for: ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ void saveBytesToFile_shouldNotThrowExceptionWhenNoDirectory(@TempDir Path tempDi
129129
final DebugDataDumper manager = new DebugDataDumper(tempDir, true);
130130
assertDoesNotThrow(
131131
() ->
132-
manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY));
132+
manager.saveBytesToFile(
133+
"object", "at slot 1", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY));
133134
}
134135

135136
@Test
@@ -141,7 +142,8 @@ void saveBytesToFile_shouldNotEscalateWhenIOException(@TempDir Path tempDir) {
141142
assertThat(invalidPath.setWritable(false)).isTrue();
142143
assertDoesNotThrow(
143144
() ->
144-
manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY));
145+
manager.saveBytesToFile(
146+
"object", "at slot 1", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY));
145147
}
146148

147149
@Test

0 commit comments

Comments
 (0)