From 46e4b284892c844bfb29fd1d0f1e64ecb81eedb1 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 23 Mar 2022 10:36:25 +0300 Subject: [PATCH] [#195] Add logger to notification controller Signed-off-by: Denis Kirillov --- api/notifications/controller.go | 10 ++++++---- cmd/s3-gw/app.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/notifications/controller.go b/api/notifications/controller.go index fb6da671..4bc3f0d5 100644 --- a/api/notifications/controller.go +++ b/api/notifications/controller.go @@ -8,6 +8,7 @@ import ( "github.com/nats-io/nats.go" "github.com/nspcc-dev/neofs-s3-gw/api/layer" + "go.uber.org/zap" ) const ( @@ -23,6 +24,7 @@ type Options struct { } type Controller struct { + logger *zap.Logger taskQueueConnection *nats.Conn jsClient nats.JetStreamContext handlers map[string]Stream @@ -34,7 +36,7 @@ type Stream struct { ch chan *nats.Msg } -func NewController(p *Options) (*Controller, error) { +func NewController(p *Options, l *zap.Logger) (*Controller, error) { if p == nil { return nil, nil } @@ -61,6 +63,7 @@ func NewController(p *Options) (*Controller, error) { } return &Controller{ + logger: l, taskQueueConnection: nc, jsClient: js, handlers: make(map[string]Stream), @@ -103,11 +106,10 @@ func (c *Controller) Listen(ctx context.Context) { for { select { case msg := <-stream.ch: - fmt.Printf("got message: %s\n", msg.Data) if err := stream.h.HandleMessage(ctx, msg); err != nil { - fmt.Printf("could not handle message: %s", err) + c.logger.Error("could not handle message", zap.Error(err)) } else if err = msg.Ack(); err != nil { - fmt.Printf("could not ACK message: %s", err) + c.logger.Error("could not ACK message", zap.Error(err)) } case <-ctx.Done(): return diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index 79a482b2..59645503 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -144,7 +144,7 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { } nopts := getNotificationsOptions(v, l) - nc, err := notifications.NewController(nopts) + nc, err := notifications.NewController(nopts, l) if err != nil { l.Fatal("failed to enable notifications", zap.Error(err)) }