Skip to content

Commit 65c27aa

Browse files
Refactoring: change logger library
1 parent c7b329e commit 65c27aa

File tree

9 files changed

+119
-104
lines changed

9 files changed

+119
-104
lines changed

database/db.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/dipdup-net/go-lib/config"
1010
"github.com/pkg/errors"
11-
"github.com/sirupsen/logrus"
11+
"github.com/rs/zerolog/log"
1212
)
1313

1414
// Database -
@@ -29,7 +29,7 @@ var (
2929

3030
// Wait -
3131
func Wait(ctx context.Context, db driver.Pinger, checkPeriod time.Duration) {
32-
logrus.Info("Waiting database is up and runnning")
32+
log.Info().Msg("Waiting database is up and runnning")
3333
if err := db.Ping(ctx); err == nil {
3434
return
3535
}
@@ -41,7 +41,7 @@ func Wait(ctx context.Context, db driver.Pinger, checkPeriod time.Duration) {
4141
return
4242
case <-ticker.C:
4343
if err := db.Ping(ctx); err == nil {
44-
logrus.Warn(err)
44+
log.Warn().Err(err).Msg("")
4545
continue
4646
}
4747
return

go.mod

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@ require (
1212
github.com/json-iterator/go v1.1.12
1313
github.com/pkg/errors v0.9.1
1414
github.com/prometheus/client_golang v1.11.0
15+
github.com/rs/zerolog v1.26.0
1516
github.com/sergi/go-diff v1.2.0
16-
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc
17-
github.com/sirupsen/logrus v1.7.0
17+
github.com/shopspring/decimal v1.3.1
1818
github.com/stretchr/testify v1.7.0
19-
github.com/tidwall/gjson v1.9.3
20-
github.com/yhirose/go-peg v0.0.0-20210119023502-a1af152bac31
21-
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
22-
golang.org/x/sys v0.0.0-20211031064116-611d5d643895 // indirect
19+
github.com/tidwall/gjson v1.12.1
20+
github.com/yhirose/go-peg v0.0.0-20210804202551-de25d6753cf1
21+
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e
22+
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
2323
golang.org/x/text v0.3.7
24-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
2524
gopkg.in/yaml.v2 v2.4.0
26-
gorm.io/driver/mysql v1.0.5
27-
gorm.io/driver/postgres v1.0.8
28-
gorm.io/driver/sqlite v1.1.4
29-
gorm.io/gorm v1.21.8
25+
gorm.io/driver/mysql v1.2.1
26+
gorm.io/driver/postgres v1.2.3
27+
gorm.io/driver/sqlite v1.2.6
28+
gorm.io/gorm v1.22.4
3029
)

go.sum

Lines changed: 75 additions & 59 deletions
Large diffs are not rendered by default.

hasura/hasura.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
"github.com/iancoleman/strcase"
1414
"github.com/pkg/errors"
1515

16-
log "github.com/sirupsen/logrus"
16+
"github.com/rs/zerolog/log"
1717
)
1818

1919
const (
2020
allowedQueries = "allowed-queries"
2121
)
2222

2323
func checkHealth(ctx context.Context, api *API) {
24-
log.Info("Waiting hasura is up and running")
24+
log.Info().Msg("Waiting hasura is up and running")
2525
if err := api.Health(ctx); err != nil {
2626
return
2727
}
@@ -32,7 +32,7 @@ func checkHealth(ctx context.Context, api *API) {
3232
return
3333
case <-ticker.C:
3434
if err := api.Health(ctx); err != nil {
35-
log.Warn(err)
35+
log.Warn().Err(err).Msg("")
3636
continue
3737
}
3838
return
@@ -54,13 +54,13 @@ func Create(ctx context.Context, hasura *config.Hasura, cfg config.Database, vie
5454
return err
5555
}
5656

57-
log.Info("Fetching existing metadata...")
57+
log.Info().Msg("Fetching existing metadata...")
5858
export, err := api.ExportMetadata(ctx, metadata)
5959
if err != nil {
6060
return err
6161
}
6262

63-
log.Info("Merging metadata...")
63+
log.Info().Msg("Merging metadata...")
6464
tables := make(map[string]struct{})
6565
for i := range metadata.Tables {
6666
tables[metadata.Tables[i].Schema.Name] = struct{}{}
@@ -76,13 +76,13 @@ func Create(ctx context.Context, hasura *config.Hasura, cfg config.Database, vie
7676
return err
7777
}
7878

79-
log.Info("Replacing metadata...")
79+
log.Info().Msg("Replacing metadata...")
8080
if err := api.ReplaceMetadata(ctx, metadata); err != nil {
8181
return err
8282
}
8383

8484
if len(metadata.QueryCollections) > 0 && (hasura.Rest == nil || *hasura.Rest) {
85-
log.Info("Creating REST endpoints...")
85+
log.Info().Msg("Creating REST endpoints...")
8686
for _, query := range metadata.QueryCollections[0].Definition.Queries {
8787
if err := api.CreateRestEndpoint(ctx, query.Name, query.Name, query.Name, allowedQueries); err != nil {
8888
if e, ok := err.(APIError); !ok || !e.AlreadyExists() {
@@ -92,15 +92,15 @@ func Create(ctx context.Context, hasura *config.Hasura, cfg config.Database, vie
9292
}
9393
}
9494

95-
log.Info("Tracking views...")
95+
log.Info().Msg("Tracking views...")
9696
for i := range views {
9797
if err := api.TrackTable(ctx, "public", views[i]); err != nil {
9898
if !strings.Contains(err.Error(), "view/table already tracked") {
9999
return err
100100
}
101101
}
102102
if err := api.DropSelectPermissions(ctx, views[i], "user"); err != nil {
103-
log.Warn(err)
103+
log.Warn().Err(err).Msg("")
104104
}
105105
if err := api.CreateSelectPermissions(ctx, views[i], "user", Permission{
106106
Limit: hasura.RowsLimit,

node/monitor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/pkg/errors"
13-
log "github.com/sirupsen/logrus"
13+
"github.com/rs/zerolog/log"
1414
)
1515

1616
const (
@@ -137,7 +137,7 @@ func (monitor *Monitor) pollingMempool(ctx context.Context, filter string) {
137137
return
138138
default:
139139
if err := monitor.process(ctx, filter, url); err != nil {
140-
log.Error(err)
140+
log.Err(err).Msg("")
141141
continue
142142
}
143143

tzkt/events/signalr/hub.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/gorilla/websocket"
1010
"github.com/pkg/errors"
11-
log "github.com/sirupsen/logrus"
11+
"github.com/rs/zerolog/log"
1212
)
1313

1414
var (
@@ -62,7 +62,7 @@ func (hub *Hub) Connect() error {
6262
}
6363

6464
func (hub *Hub) handshake() error {
65-
log.Tracef("connecting to %s...", hub.url.String())
65+
log.Trace().Msgf("connecting to %s...", hub.url.String())
6666

6767
c, _, err := websocket.DefaultDialer.Dial(hub.url.String(), nil)
6868
if err != nil {
@@ -82,7 +82,7 @@ func (hub *Hub) handshake() error {
8282
if resp.Error != "" {
8383
return errors.Wrap(ErrHandshake, resp.Error)
8484
}
85-
log.Trace("connected")
85+
log.Trace().Msg("connected")
8686

8787
return nil
8888
}
@@ -106,16 +106,16 @@ func (hub *Hub) Close() error {
106106
}
107107

108108
func (hub *Hub) reconnect() error {
109-
log.Warn("reconnecting...")
109+
log.Warn().Msg("reconnecting...")
110110

111111
if err := hub.Send(newCloseMessage()); err != nil {
112-
log.Error(err)
112+
log.Err(err).Msg("send")
113113
}
114114

115115
if err := hub.conn.Close(); err != nil {
116-
log.Error(err)
116+
log.Err(err).Msg("close")
117117
}
118-
log.Trace("connection closed")
118+
log.Trace().Msg("connection closed")
119119
if err := hub.handshake(); err != nil {
120120
return err
121121
}
@@ -140,13 +140,13 @@ func (hub *Hub) listen() {
140140
switch {
141141
case errors.Is(err, ErrTimeout) || websocket.IsCloseError(err, websocket.CloseAbnormalClosure):
142142
if err := hub.reconnect(); err != nil {
143-
log.Errorf("reconnect: %s", err.Error())
144-
log.Warn("retry after 5 seconds")
143+
log.Err(err).Msg("reconnect")
144+
log.Warn().Msg("retry after 5 seconds")
145145
time.Sleep(time.Second * 5)
146146
}
147147
case errors.Is(err, ErrEmptyResponse):
148148
default:
149-
log.Errorf("readAllMessages: %s", err.Error())
149+
log.Err(err).Msg("readAllMessages")
150150
}
151151
}
152152
}
@@ -198,7 +198,7 @@ func (hub *Hub) readAllMessages() error {
198198
return err
199199
}
200200
if scanner == nil {
201-
log.Warn("No messages during read timeout")
201+
log.Warn().Msg("no messages during read timeout")
202202
return ErrEmptyResponse
203203
}
204204
if err := scanner.Scan(); err != nil {
@@ -233,7 +233,7 @@ func (hub *Hub) readAllMessages() error {
233233

234234
func (hub *Hub) closeMessageHandler(msg CloseMessage) error {
235235
if msg.Error != "" {
236-
log.Error(msg.Error)
236+
log.Error().Msg(msg.Error)
237237
}
238238
if !msg.AllowReconnect {
239239
return ErrConnectionClose

tzkt/events/signalr/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
jsoniter "github.com/json-iterator/go"
99
"github.com/pkg/errors"
10-
log "github.com/sirupsen/logrus"
10+
"github.com/rs/zerolog/log"
1111
)
1212

1313
var json = jsoniter.ConfigCompatibleWithStandardLibrary
@@ -28,7 +28,7 @@ func NewJSONEncoding() *JSONEncoding {
2828

2929
// Decode -
3030
func (e *JSONEncoding) Decode(data []byte) (interface{}, error) {
31-
log.Trace(string(data))
31+
log.Trace().Msg(string(data))
3232

3333
var typ Type
3434
if err := json.Unmarshal(data, &typ); err != nil {

tzkt/events/signalr/transport.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"net/http"
55
"net/url"
66

7-
log "github.com/sirupsen/logrus"
7+
"github.com/rs/zerolog/log"
88

99
"github.com/pkg/errors"
1010
)
@@ -41,7 +41,7 @@ func (t *Transport) Negotiate(version Version) (response NegotiateResponse, err
4141
q.Set("negotiateVersion", string(version))
4242
u.RawQuery = q.Encode()
4343

44-
log.WithField("url", u.String()).Trace("Send negotiate request...")
44+
log.Trace().Str("url", u.String()).Msg("send negotiate request...")
4545

4646
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
4747
if err != nil {

tzkt/events/tzkt.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/dipdup-net/go-lib/tzkt/events/signalr"
1010
"github.com/pkg/errors"
11-
log "github.com/sirupsen/logrus"
11+
"github.com/rs/zerolog/log"
1212
)
1313

1414
// TzKT - struct that used for connection to TzKT events server
@@ -141,13 +141,13 @@ func (tzkt *TzKT) listen() {
141141
switch typ := msg.(type) {
142142
case signalr.Invocation:
143143
if len(typ.Arguments) == 0 {
144-
log.Warnf("Empty arguments of invocation: %v", typ)
144+
log.Warn().Msgf("empty arguments of invocation: %v", typ)
145145
continue
146146
}
147147

148148
var packet Packet
149149
if err := json.Unmarshal(typ.Arguments[0], &packet); err != nil {
150-
log.WithError(err).Error("invalid invocation argument")
150+
log.Err(err).Msg("invalid invocation argument")
151151
continue
152152
}
153153

@@ -160,7 +160,7 @@ func (tzkt *TzKT) listen() {
160160
if packet.Data != nil {
161161
data, err := parseData(typ.Target, packet.Data)
162162
if err != nil {
163-
log.WithError(err).Error("error during parsing data")
163+
log.Err(err).Msg("error during parsing data")
164164
continue
165165
}
166166
message.Body = data

0 commit comments

Comments
 (0)