Skip to content

Commit e10ee75

Browse files
authored
feat: migrate to structured logging (#11)
1 parent cbe6c1a commit e10ee75

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/main/java/io/statnett/k3a/topicterminator/TopicTerminator.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public TopicTerminator(ApplicationProperties props, KafkaAdmin kafkaAdmin) {
3131

3232
@Scheduled(fixedRateString = "${app.fixed-rate-string}")
3333
public void terminateUnusedTopics() throws ExecutionException, InterruptedException {
34-
log.info("Terminating unused topics{}", props.isDryRun() ? " in dry-run mode" : "");
34+
log.atInfo()
35+
.setMessage("Terminating unused topics")
36+
.addKeyValue("dry-run", props.isDryRun())
37+
.log();
3538
try (AdminClient client = AdminClient.create(kafkaAdmin.getConfigurationProperties())) {
3639
final Set<String> allTopics = client.listTopics().names().get();
3740

@@ -47,11 +50,20 @@ public void terminateUnusedTopics() throws ExecutionException, InterruptedExcept
4750
unusedTopics.removeAll(reservedTopic.getNames(client));
4851
}
4952

50-
log.info("{} topic(s) to be deleted: ", unusedTopics.size());
53+
log.atInfo()
54+
.setMessage("Start deleting unused topics")
55+
.addKeyValue("count", unusedTopics.size())
56+
.log();
5157
if (props.isDryRun()) {
52-
unusedTopics.forEach(t -> log.info("Topic {} is considered unused and would be deleted in non dry-run mode", t));
58+
unusedTopics.forEach(t -> log.atInfo()
59+
.setMessage("NOT deleting unused topic in dry-run mode")
60+
.addKeyValue("topic", t)
61+
.log());
5362
} else {
54-
unusedTopics.forEach(t -> log.info("Delete unused topic: {}", t));
63+
unusedTopics.forEach(t -> log.atInfo()
64+
.setMessage("Deleting unused topic")
65+
.addKeyValue("topic", t)
66+
.log());
5567
client.deleteTopics(unusedTopics);
5668
}
5769
}

0 commit comments

Comments
 (0)