Skip to content

Commit a83992d

Browse files
danvixentjirevwe
andauthored
use central logger everywhere (frain-dev#1176)
* feat: add stdLogger * feat: switch to central logger everywhere * fix: fix lint * feat: inject request id into log * feat: remove NextSendTime comment * fix: - remove SetLogger - new logger for worker Co-authored-by: Raymond Tukpe <jirevwe@users.noreply.github.com>
1 parent 3b2a9ae commit a83992d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+329
-182
lines changed

analytics/active_group_analytics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66

77
"github.com/frain-dev/convoy/datastore"
8-
log "github.com/sirupsen/logrus"
8+
"github.com/frain-dev/convoy/pkg/log"
99
)
1010

1111
type ActiveGroupAnalytics struct {

analytics/analytics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/frain-dev/convoy/config"
1010
"github.com/frain-dev/convoy/datastore"
1111
cm "github.com/frain-dev/convoy/datastore/mongo"
12+
"github.com/frain-dev/convoy/pkg/log"
1213
"github.com/google/uuid"
1314
"github.com/hibiken/asynq"
14-
log "github.com/sirupsen/logrus"
1515
)
1616

1717
const (

analytics/event_analytics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66

77
"github.com/frain-dev/convoy/datastore"
8-
log "github.com/sirupsen/logrus"
8+
"github.com/frain-dev/convoy/pkg/log"
99
)
1010

1111
type EventAnalytics struct {

auth/realm_chain/realm_chain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/frain-dev/convoy/cache"
1414
"github.com/frain-dev/convoy/config"
1515
"github.com/frain-dev/convoy/datastore"
16-
log "github.com/sirupsen/logrus"
16+
"github.com/frain-dev/convoy/pkg/log"
1717
)
1818

1919
type chainMap map[string]auth.Realm

cmd/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"fmt"
66

77
"github.com/frain-dev/convoy/config"
8-
log "github.com/sirupsen/logrus"
8+
"github.com/frain-dev/convoy/pkg/log"
9+
910
"github.com/spf13/cobra"
1011
)
1112

cmd/listen.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ import (
1616
"github.com/frain-dev/convoy"
1717
"github.com/frain-dev/convoy/internal/pkg/socket"
1818
convoyNet "github.com/frain-dev/convoy/net"
19+
"github.com/frain-dev/convoy/pkg/log"
1920
"github.com/frain-dev/convoy/util"
2021
"github.com/gorilla/websocket"
21-
log "github.com/sirupsen/logrus"
22+
2223
"github.com/spf13/cobra"
2324
"gopkg.in/yaml.v3"
2425
)
2526

26-
var done chan interface{}
27-
var interrupt chan os.Signal
27+
var (
28+
done chan interface{}
29+
interrupt chan os.Signal
30+
)
2831

2932
const (
3033
// Time allowed to write a message to the server.
@@ -103,7 +106,6 @@ func addListenCommand(a *app) *cobra.Command {
103106
"Authorization": []string{"Bearer " + c.ActiveApiKey},
104107
"Body": []string{string(body)},
105108
})
106-
107109
if err != nil {
108110
if response != nil {
109111
buf, e := io.ReadAll(response.Body)
@@ -131,7 +133,7 @@ func addListenCommand(a *app) *cobra.Command {
131133
// Send a message to the server to resend unsuccessful events to the device
132134
err := conn.WriteMessage(websocket.TextMessage, []byte(since))
133135
if err != nil {
134-
log.Println("an error occured sending 'since' message", err)
136+
log.WithError(err).Errorln("an error occurred sending 'since' message")
135137
}
136138
}
137139

@@ -142,7 +144,7 @@ func addListenCommand(a *app) *cobra.Command {
142144
case <-ticker.C:
143145
err := conn.SetWriteDeadline(time.Now().Add(writeWait))
144146
if err != nil {
145-
log.Println(err)
147+
log.WithError(err).Errorln("failed to set write deadline")
146148
}
147149

148150
if err := conn.WriteMessage(websocket.PingMessage, nil); err != nil {
@@ -159,14 +161,14 @@ func addListenCommand(a *app) *cobra.Command {
159161
// Send a message to set the device to offline
160162
err := conn.WriteMessage(websocket.TextMessage, []byte("disconnect"))
161163
if err != nil {
162-
log.Println("Error during closing websocket:", err)
164+
log.WithError(err).Errorln("error during closing websocket")
163165
return
164166
}
165167

166168
// Close our websocket connection
167169
err = conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
168170
if err != nil {
169-
log.Println("Error during closing websocket:", err)
171+
log.WithError(err).Errorln("error during closing websocket")
170172
return
171173
}
172174

cmd/login.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/spf13/cobra"
1818
"gopkg.in/yaml.v3"
1919

20-
log "github.com/sirupsen/logrus"
20+
"github.com/frain-dev/convoy/pkg/log"
2121
)
2222

2323
const (
@@ -133,7 +133,7 @@ func addLoginCommand() *cobra.Command {
133133

134134
var response *socket.LoginResponse
135135

136-
dispatch, err := convoyNet.NewDispatcher(time.Second * 10, "")
136+
dispatch, err := convoyNet.NewDispatcher(time.Second*10, "")
137137
if err != nil {
138138
return err
139139
}

cmd/migrate.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
"github.com/frain-dev/convoy/config"
99
cm "github.com/frain-dev/convoy/datastore/mongo"
1010
"github.com/frain-dev/convoy/internal/pkg/migrate"
11-
log "github.com/sirupsen/logrus"
11+
"github.com/frain-dev/convoy/pkg/log"
12+
1213
"github.com/spf13/cobra"
1314
"go.mongodb.org/mongo-driver/mongo"
1415
)

cmd/retry.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package main
33
import (
44
"github.com/frain-dev/convoy/config"
55
"github.com/frain-dev/convoy/datastore"
6+
"github.com/frain-dev/convoy/pkg/log"
67
"github.com/frain-dev/convoy/worker/task"
7-
log "github.com/sirupsen/logrus"
8+
89
"github.com/spf13/cobra"
910
)
1011

cmd/server.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"errors"
5+
"os"
56
"time"
67

78
"github.com/frain-dev/convoy"
@@ -186,7 +187,7 @@ func StartConvoyServer(a *app, cfg config.Configuration, withWorkers bool) error
186187
return err
187188
}
188189

189-
lo := a.logger.(*log.Logger)
190+
lo := log.NewLogger(os.Stdout)
190191
lo.SetPrefix("worker")
191192

192193
lvl, err := log.ParseLevel(cfg.Logger.Level)
@@ -245,7 +246,7 @@ func StartConvoyServer(a *app, cfg config.Configuration, withWorkers bool) error
245246
consumer.RegisterHandlers(convoy.IndexDocument, task.SearchIndex(a.searcher))
246247
consumer.RegisterHandlers(convoy.NotificationProcessor, task.ProcessNotifications(sc))
247248

248-
//start worker
249+
// start worker
249250
a.logger.Infof("Starting Convoy workers...")
250251
consumer.Start()
251252
}

cmd/switch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/frain-dev/convoy/util"
99
"github.com/spf13/cobra"
1010

11-
log "github.com/sirupsen/logrus"
11+
"github.com/frain-dev/convoy/pkg/log"
1212
)
1313

1414
func addSwitchCommand() *cobra.Command {

config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"strings"
1010
"sync/atomic"
1111

12+
"github.com/frain-dev/convoy/pkg/log"
1213
"github.com/kelseyhightower/envconfig"
13-
log "github.com/sirupsen/logrus"
1414
)
1515

1616
const (

datastore/db.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"reflect"
77
"time"
88

9+
"github.com/frain-dev/convoy/pkg/log"
910
pager "github.com/gobeam/mongo-go-pagination"
10-
log "github.com/sirupsen/logrus"
11+
1112
"go.mongodb.org/mongo-driver/bson"
1213
"go.mongodb.org/mongo-driver/bson/primitive"
1314
"go.mongodb.org/mongo-driver/mongo"

datastore/mongo/application.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"time"
88

99
"github.com/frain-dev/convoy/datastore"
10+
"github.com/frain-dev/convoy/pkg/log"
1011
"github.com/frain-dev/convoy/util"
1112
"github.com/google/uuid"
12-
log "github.com/sirupsen/logrus"
1313

1414
"go.mongodb.org/mongo-driver/bson"
1515
"go.mongodb.org/mongo-driver/bson/primitive"

datastore/mongo/event.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"time"
88

99
"github.com/frain-dev/convoy/datastore"
10+
"github.com/frain-dev/convoy/pkg/log"
1011
"github.com/frain-dev/convoy/util"
1112
"github.com/google/uuid"
12-
log "github.com/sirupsen/logrus"
13+
1314
"go.mongodb.org/mongo-driver/bson"
1415
"go.mongodb.org/mongo-driver/bson/primitive"
1516
"go.mongodb.org/mongo-driver/mongo"

datastore/mongo/group.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/frain-dev/convoy/util"
1010

11-
log "github.com/sirupsen/logrus"
11+
"github.com/frain-dev/convoy/pkg/log"
1212

1313
"github.com/frain-dev/convoy/datastore"
1414
"go.mongodb.org/mongo-driver/bson"

datastore/mongo/mongo.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"strings"
77
"time"
88

9-
log "github.com/sirupsen/logrus"
9+
"github.com/frain-dev/convoy/pkg/log"
10+
1011
"go.mongodb.org/mongo-driver/bson"
1112

1213
"github.com/frain-dev/convoy/config"

datastore/mongo/organisation_member.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"time"
77

88
"github.com/frain-dev/convoy/datastore"
9+
"github.com/frain-dev/convoy/pkg/log"
910
"github.com/frain-dev/convoy/util"
10-
log "github.com/sirupsen/logrus"
11+
1112
"go.mongodb.org/mongo-driver/bson"
1213
"go.mongodb.org/mongo-driver/bson/primitive"
1314
"go.mongodb.org/mongo-driver/mongo"

datastore/object-store/onprem.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package objectstore
33
import (
44
"os"
55

6-
log "github.com/sirupsen/logrus"
6+
"github.com/frain-dev/convoy/pkg/log"
77
)
88

99
type OnPremClient struct {

datastore/object-store/s3.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/aws/aws-sdk-go/aws/credentials"
99
"github.com/aws/aws-sdk-go/aws/session"
1010
"github.com/aws/aws-sdk-go/service/s3/s3manager"
11-
log "github.com/sirupsen/logrus"
11+
"github.com/frain-dev/convoy/pkg/log"
1212
)
1313

1414
type S3Client struct {

docs/docs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Package docs GENERATED BY SWAG; DO NOT EDIT
22
// This file was generated by swaggo/swag at
3-
// 2022-11-22 23:20:51.310822 +0000 GMT m=+1.399094418
3+
// 2022-11-23 16:22:24.197385 +0000 GMT m=+1.449902751
4+
45
package docs
56

67
import "github.com/swaggo/swag"

internal/notifications/notifications.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/frain-dev/convoy"
1010
"github.com/frain-dev/convoy/datastore"
1111
"github.com/frain-dev/convoy/internal/email"
12+
"github.com/frain-dev/convoy/pkg/log"
1213
"github.com/frain-dev/convoy/queue"
1314
"github.com/frain-dev/convoy/util"
14-
log "github.com/sirupsen/logrus"
1515
)
1616

1717
type NotificationType string

internal/pkg/fflag/feature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"github.com/frain-dev/convoy/datastore"
1212
"github.com/frain-dev/convoy/internal/pkg/fflag/flipt"
1313
"github.com/frain-dev/convoy/internal/pkg/middleware"
14+
"github.com/frain-dev/convoy/pkg/log"
1415
"github.com/frain-dev/convoy/server/models"
1516
"github.com/frain-dev/convoy/util"
1617
"github.com/go-chi/render"
17-
log "github.com/sirupsen/logrus"
1818
)
1919

2020
type IsEnabledFunc func(r *http.Request) error

internal/pkg/middleware/middleware.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,13 @@ func (m *Middleware) LogHttpRequest() func(next http.Handler) http.Handler {
901901
m.logger.WithError(err).Error("Failed to generate status level")
902902
}
903903

904-
m.logger.WithLogger().WithFields(logFields).Log(lvl, requestFields["requestURL"])
904+
m.logger.WithFields(logFields).Log(lvl, requestFields["requestURL"])
905905
}()
906906

907+
requestID := middleware.GetReqID(r.Context())
908+
ctx := log.NewContext(r.Context(), m.logger, log.Fields{"request_id": requestID})
909+
r = r.WithContext(ctx)
910+
907911
next.ServeHTTP(ww, r)
908912
})
909913
}

internal/pkg/migrate/migrate.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"fmt"
77

88
"github.com/frain-dev/convoy/datastore"
9-
log "github.com/sirupsen/logrus"
9+
"github.com/frain-dev/convoy/pkg/log"
10+
1011
"go.mongodb.org/mongo-driver/bson"
1112
"go.mongodb.org/mongo-driver/mongo"
1213
)

internal/pkg/migrate/migrations.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"go.mongodb.org/mongo-driver/bson/primitive"
1010

1111
"github.com/frain-dev/convoy/datastore"
12-
log "github.com/sirupsen/logrus"
12+
"github.com/frain-dev/convoy/pkg/log"
1313

1414
"go.mongodb.org/mongo-driver/bson"
1515
"go.mongodb.org/mongo-driver/mongo"

internal/pkg/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010

1111
"github.com/frain-dev/convoy"
1212
"github.com/frain-dev/convoy/internal/pkg/middleware"
13+
"github.com/frain-dev/convoy/pkg/log"
1314
"github.com/frain-dev/convoy/util"
1415
"github.com/go-chi/chi/v5"
1516
"github.com/go-chi/render"
16-
log "github.com/sirupsen/logrus"
1717
)
1818

1919
type Server struct {

internal/pkg/smtp/smtp.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"fmt"
77

88
"github.com/frain-dev/convoy/config"
9+
"github.com/frain-dev/convoy/pkg/log"
910
"github.com/frain-dev/convoy/util"
10-
log "github.com/sirupsen/logrus"
11+
1112
"gopkg.in/gomail.v2"
1213
)
1314

internal/pkg/socket/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"time"
1010

1111
"github.com/frain-dev/convoy/datastore"
12+
"github.com/frain-dev/convoy/pkg/log"
1213
"github.com/gorilla/websocket"
13-
log "github.com/sirupsen/logrus"
1414
)
1515

1616
const (

internal/pkg/socket/handlers.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414
"github.com/gorilla/websocket"
1515

1616
"github.com/frain-dev/convoy/datastore"
17+
"github.com/frain-dev/convoy/pkg/log"
1718
"github.com/frain-dev/convoy/util"
1819
"github.com/google/uuid"
19-
log "github.com/sirupsen/logrus"
20+
2021
"go.mongodb.org/mongo-driver/bson/primitive"
2122
)
2223

0 commit comments

Comments
 (0)