Skip to content

Commit

Permalink
Replace logrus with slog in handlers packages
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Oct 12, 2023
1 parent 56a4ad4 commit 246be69
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions handlers/facebook_legacy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"log/slog"
"net/http"
"net/url"
"strings"
Expand All @@ -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
Expand Down Expand Up @@ -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())

Check warning on line 127 in handlers/facebook_legacy/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/facebook_legacy/handler.go#L127

Added line #L127 was not covered by tests
}

h.Backend().WriteChannelLog(ctx, clog)
Expand Down
4 changes: 2 additions & 2 deletions handlers/hormuud/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"net/http"
"net/url"
"strings"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

var (
Expand Down Expand Up @@ -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)

Check warning on line 184 in handlers/hormuud/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/hormuud/handler.go#L184

Added line #L184 was not covered by tests
}

return token, nil
Expand Down
4 changes: 2 additions & 2 deletions handlers/messagebird/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"log/slog"
"strconv"

"fmt"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)

Check warning on line 116 in handlers/messagebird/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/messagebird/handler.go#L116

Added line #L116 was not covered by tests
} else {
status = h.Backend().NewStatusUpdate(channel, courier.MsgID(msgID), msgStatus, clog)
}
Expand Down
4 changes: 2 additions & 2 deletions handlers/twiml/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
_ "embed"
"encoding/base64"
"fmt"
"log/slog"
"net/http"
"net/url"
"sort"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/urns"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions handlers/whatsapp_legacy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"net/http"
"net/url"
"strconv"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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())

Check warning on line 580 in handlers/whatsapp_legacy/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/whatsapp_legacy/handler.go#L580

Added line #L580 was not covered by tests
}
fileURL := mediaURL
if err == nil && mediaID != "" {
Expand All @@ -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())

Check warning on line 607 in handlers/whatsapp_legacy/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/whatsapp_legacy/handler.go#L607

Added line #L607 was not covered by tests
}
payload.Document = mediaPayload
payloads = append(payloads, payload)
Expand Down

0 comments on commit 246be69

Please sign in to comment.