Skip to content

Commit fcf85ac

Browse files
authored
Not omit error in logger (#1096)
Add explicit errors as arguments so anyone can handle them in the logger implementation.
1 parent ceb95ed commit fcf85ac

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

reader.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (r *Reader) commitLoopInterval(ctx context.Context, gen *Generation) {
238238

239239
commit := func() {
240240
if err := r.commitOffsetsWithRetry(gen, offsets, defaultCommitRetries); err != nil {
241-
r.withErrorLogger(func(l Logger) { l.Printf(err.Error()) })
241+
r.withErrorLogger(func(l Logger) { l.Printf("%v", err) })
242242
} else {
243243
offsets.reset()
244244
}
@@ -311,7 +311,7 @@ func (r *Reader) run(cg *ConsumerGroup) {
311311
}
312312
r.stats.errors.observe(1)
313313
r.withErrorLogger(func(l Logger) {
314-
l.Printf(err.Error())
314+
l.Printf("%v", err)
315315
})
316316
// Continue with next attempt...
317317
}
@@ -1346,7 +1346,7 @@ func (r *reader) run(ctx context.Context, offset int64) {
13461346

13471347
case errors.Is(err, UnknownTopicOrPartition):
13481348
r.withErrorLogger(func(log Logger) {
1349-
log.Printf("failed to read from current broker for partition %d of %s at offset %d, topic or parition not found on this broker, %v", r.partition, r.topic, toHumanOffset(offset), r.brokers)
1349+
log.Printf("failed to read from current broker %v for partition %d of %s at offset %d: %v", r.brokers, r.partition, r.topic, toHumanOffset(offset), err)
13501350
})
13511351

13521352
conn.Close()
@@ -1358,7 +1358,7 @@ func (r *reader) run(ctx context.Context, offset int64) {
13581358

13591359
case errors.Is(err, NotLeaderForPartition):
13601360
r.withErrorLogger(func(log Logger) {
1361-
log.Printf("failed to read from current broker for partition %d of %s at offset %d, not the leader", r.partition, r.topic, toHumanOffset(offset))
1361+
log.Printf("failed to read from current broker for partition %d of %s at offset %d: %v", r.partition, r.topic, toHumanOffset(offset), err)
13621362
})
13631363

13641364
conn.Close()
@@ -1372,7 +1372,7 @@ func (r *reader) run(ctx context.Context, offset int64) {
13721372
// Timeout on the kafka side, this can be safely retried.
13731373
errcount = 0
13741374
r.withLogger(func(log Logger) {
1375-
log.Printf("no messages received from kafka within the allocated time for partition %d of %s at offset %d", r.partition, r.topic, toHumanOffset(offset))
1375+
log.Printf("no messages received from kafka within the allocated time for partition %d of %s at offset %d: %v", r.partition, r.topic, toHumanOffset(offset), err)
13761376
})
13771377
r.stats.timeouts.observe(1)
13781378
continue

0 commit comments

Comments
 (0)