Skip to content

Commit e5e2ba6

Browse files
authored
fix: consumer pkg uses proper logger (#591)
1 parent ceb82d5 commit e5e2ba6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

internal/consumer/consumer.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package consumer
22

33
import (
44
"context"
5-
"log"
65

6+
"github.com/hookdeck/outpost/internal/logging"
77
"github.com/hookdeck/outpost/internal/mqs"
88
"go.opentelemetry.io/otel"
9+
"go.uber.org/zap"
910
)
1011

1112
type Consumer interface {
@@ -19,6 +20,7 @@ type MessageHandler interface {
1920
type consumerImplOptions struct {
2021
name string
2122
concurrency int
23+
logger *logging.Logger
2224
}
2325

2426
func WithName(name string) func(*consumerImplOptions) {
@@ -33,6 +35,12 @@ func WithConcurrency(concurrency int) func(*consumerImplOptions) {
3335
}
3436
}
3537

38+
func WithLogger(logger *logging.Logger) func(*consumerImplOptions) {
39+
return func(c *consumerImplOptions) {
40+
c.logger = logger
41+
}
42+
}
43+
3644
func New(subscription mqs.Subscription, handler MessageHandler, opts ...func(*consumerImplOptions)) Consumer {
3745
options := &consumerImplOptions{
3846
name: "",
@@ -86,10 +94,11 @@ recvLoop:
8694
defer span.End()
8795

8896
err = c.handler.Handle(handlerCtx, msg)
89-
// TODO: error handling?
9097
if err != nil {
9198
span.RecordError(err)
92-
log.Printf("consumer handler error: %v", err)
99+
if c.logger != nil {
100+
c.logger.Ctx(handlerCtx).Error("consumer handler error", zap.String("name", c.name), zap.Error(err))
101+
}
93102
}
94103
}()
95104
}

internal/services/consumer_worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (w *ConsumerWorker) Run(ctx context.Context) error {
5757
csm := consumer.New(subscription, w.handler,
5858
consumer.WithName(w.name),
5959
consumer.WithConcurrency(w.concurrency),
60+
consumer.WithLogger(w.logger),
6061
)
6162

6263
if err := csm.Run(ctx); err != nil {

0 commit comments

Comments
 (0)