Skip to content

Commit d76781d

Browse files
committed
ConsumerRecord Logging Improvement
S-I-K does not need to use a thread local for this purpose.
1 parent d5f579e commit d76781d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spring-kafka/src/main/java/org/springframework/kafka/listener/ListenerUtils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,22 @@ public static String recordToString(ConsumerRecord<?, ?> record) {
125125
}
126126
}
127127

128+
/**
129+
* Return the {@link ConsumerRecord} as a String; either {@code toString()} or
130+
* {@code topic-partition@offset}.
131+
* @param record the record.
132+
* @param meta true to log just the metadata.
133+
* @return the rendered record.
134+
* @since 2.5.4
135+
*/
136+
public static String recordToString(ConsumerRecord<?, ?> record, boolean meta) {
137+
if (meta) {
138+
return record.topic() + "-" + record.partition() + "@" + record.offset();
139+
}
140+
else {
141+
return record.toString();
142+
}
143+
}
144+
128145
}
129146

0 commit comments

Comments
 (0)