From 246be698536dd3bf639d46502d4e30dbe1da1e84 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Thu, 12 Oct 2023 13:58:38 +0200 Subject: [PATCH] Replace logrus with slog in handlers packages --- handlers/facebook_legacy/handler.go | 4 ++-- handlers/hormuud/handler.go | 4 ++-- handlers/messagebird/handler.go | 4 ++-- handlers/twiml/handlers.go | 4 ++-- handlers/whatsapp_legacy/handler.go | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/handlers/facebook_legacy/handler.go b/handlers/facebook_legacy/handler.go index c5ca9e671..6c075869a 100644 --- a/handlers/facebook_legacy/handler.go +++ b/handlers/facebook_legacy/handler.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "log/slog" "net/http" "net/url" "strings" @@ -16,7 +17,6 @@ import ( "github.com/nyaruka/gocommon/jsonx" "github.com/nyaruka/gocommon/urns" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) // Endpoints we hit @@ -124,7 +124,7 @@ func (h *handler) subscribeToEvents(ctx context.Context, channel courier.Channel // log if we get any kind of error success, _ := jsonparser.GetBoolean(respBody, "success") if err != nil || resp.StatusCode/100 != 2 || !success { - logrus.WithField("channel_uuid", channel.UUID()).Error("error subscribing to Facebook page events") + slog.Error("error subscribing to Facebook page events", "channel_uuid", channel.UUID()) } h.Backend().WriteChannelLog(ctx, clog) diff --git a/handlers/hormuud/handler.go b/handlers/hormuud/handler.go index 31dcac41c..88f8390a6 100644 --- a/handlers/hormuud/handler.go +++ b/handlers/hormuud/handler.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "log/slog" "net/http" "net/url" "strings" @@ -14,7 +15,6 @@ import ( "github.com/nyaruka/courier" "github.com/nyaruka/courier/handlers" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) var ( @@ -181,7 +181,7 @@ func (h *handler) FetchToken(ctx context.Context, channel courier.Channel, msg c conn.Close() if err != nil { - logrus.WithError(err).Error("error caching HM access token") + slog.Error("error caching HM access token", "error", err) } return token, nil diff --git a/handlers/messagebird/handler.go b/handlers/messagebird/handler.go index 4b01076aa..1981be45e 100644 --- a/handlers/messagebird/handler.go +++ b/handlers/messagebird/handler.go @@ -9,6 +9,7 @@ import ( "crypto/hmac" "crypto/sha256" "encoding/hex" + "log/slog" "strconv" "fmt" @@ -22,7 +23,6 @@ import ( "github.com/nyaruka/courier/handlers" "github.com/nyaruka/gocommon/jsonx" "github.com/nyaruka/gocommon/urns" - "github.com/sirupsen/logrus" ) var ( @@ -113,7 +113,7 @@ func (h *handler) receiveStatus(ctx context.Context, channel courier.Channel, w if receivedStatus.Reference != "" { msgID, err := strconv.ParseInt(receivedStatus.Reference, 10, 64) if err != nil { - logrus.WithError(err).WithField("id", receivedStatus.Reference).Error("error converting Messagebird status id to integer") + slog.Error("error converting Messagebird status id to integer", "error", err, "id", receivedStatus.Reference) } else { status = h.Backend().NewStatusUpdate(channel, courier.MsgID(msgID), msgStatus, clog) } diff --git a/handlers/twiml/handlers.go b/handlers/twiml/handlers.go index 4d12f6553..24298b361 100644 --- a/handlers/twiml/handlers.go +++ b/handlers/twiml/handlers.go @@ -12,6 +12,7 @@ import ( _ "embed" "encoding/base64" "fmt" + "log/slog" "net/http" "net/url" "sort" @@ -25,7 +26,6 @@ import ( "github.com/nyaruka/gocommon/httpx" "github.com/nyaruka/gocommon/urns" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) const ( @@ -181,7 +181,7 @@ func (h *handler) receiveStatus(ctx context.Context, channel courier.Channel, w if idString != "" { msgID, err := strconv.ParseInt(idString, 10, 64) if err != nil { - logrus.WithError(err).WithField("id", idString).Error("error converting twilio callback id to integer") + slog.Error("error converting twilio callback id to integer", "error", err, "id", idString) } else { status = h.Backend().NewStatusUpdate(channel, courier.MsgID(msgID), msgStatus, clog) } diff --git a/handlers/whatsapp_legacy/handler.go b/handlers/whatsapp_legacy/handler.go index b1de6774b..d03e70250 100644 --- a/handlers/whatsapp_legacy/handler.go +++ b/handlers/whatsapp_legacy/handler.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "log/slog" "net/http" "net/url" "strconv" @@ -23,7 +24,6 @@ import ( "github.com/nyaruka/redisx" "github.com/patrickmn/go-cache" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/mod/semver" ) @@ -577,7 +577,7 @@ func buildPayloads(msg courier.MsgOut, h *handler, clog *courier.ChannelLog) ([] mimeType, mediaURL := handlers.SplitAttachment(attachment) mediaID, err := h.fetchMediaID(msg, mimeType, mediaURL, clog) if err != nil { - logrus.WithField("channel_uuid", msg.Channel().UUID()).WithError(err).Error("error while uploading media to whatsapp") + slog.Error("error while uploading media to whatsapp", "error", err, "channel_uuid", msg.Channel().UUID()) } fileURL := mediaURL if err == nil && mediaID != "" { @@ -604,7 +604,7 @@ func buildPayloads(msg courier.MsgOut, h *handler, clog *courier.ChannelLog) ([] // Logging error if err != nil { - logrus.WithField("channel_uuid", msg.Channel().UUID()).WithError(err).Error("Error while parsing the media URL") + slog.Error("Error while parsing the media URL", "error", err, "channel_uuid", msg.Channel().UUID()) } payload.Document = mediaPayload payloads = append(payloads, payload)