Skip to content

Commit 92ac135

Browse files
committed
Update to use sirupsen/logrus
This new model forces vendor go files to use `sirupsen/logrus` instead of `Sirupsen/logrus` by running the new script `hack/force-github.com-sirupsen-logrus.sh`. This change also removes the use of dlog and updates to the latest logrus. Signed-off-by: Luis Pabón <[email protected]>
1 parent 3032a50 commit 92ac135

File tree

331 files changed

+72057
-27011
lines changed

Some content is hidden

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

331 files changed

+72057
-27011
lines changed

STYLEGUIDE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ IF YOU CODE ON OPENSTORAGE, YOU ARE EXPECTED TO KNOW THIS. Just take the 20 minu
2020

2121
### Items
2222

23-
* Use [dlog](https://go.pedge.io/dlog) for logging.
23+
* Use [logrus](https://github.com/sirupsen/logrus) for logging.
2424

2525
* File order:
2626

alert/alert_kvdb.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package alert
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/libopenstorage/openstorage/api"
7-
"github.com/libopenstorage/openstorage/pkg/proto/time"
8-
"github.com/portworx/kvdb"
9-
"go.pedge.io/dlog"
106
"strconv"
117
"strings"
128
"sync"
139
"time"
10+
11+
"github.com/libopenstorage/openstorage/api"
12+
"github.com/libopenstorage/openstorage/pkg/proto/time"
13+
"github.com/portworx/kvdb"
14+
"github.com/sirupsen/logrus"
1415
)
1516

1617
const (
@@ -285,15 +286,15 @@ func (kva *KvAlert) raiseIfNotExist(a *api.Alert) error {
285286
// is able to proceed.
286287
kvp, err := kv.Lock(getLockId(a.ResourceId, a.UniqueTag))
287288
if err != nil {
288-
dlog.Errorf("Failed to get lock for resource %s, err: %s",
289+
logrus.Errorf("Failed to get lock for resource %s, err: %s",
289290
a.ResourceId, err.Error())
290291
return err
291292
}
292293
defer kv.Unlock(kvp)
293294

294295
alerts, err := kva.getResourceSpecificAlerts(a.Resource, kv)
295296
if err != nil {
296-
dlog.Infof("Failed to get alerts of type %s, error: %s",
297+
logrus.Infof("Failed to get alerts of type %s, error: %s",
297298
a.Resource, err.Error())
298299
return err
299300
}
@@ -324,15 +325,15 @@ func (kva *KvAlert) ClearByUniqueTag(
324325

325326
kvp, err := kv.Lock(getLockId(resourceId, uniqueTag))
326327
if err != nil {
327-
dlog.Errorf("Failed to get lock for resource %s, err: %s",
328+
logrus.Errorf("Failed to get lock for resource %s, err: %s",
328329
resourceId, err.Error())
329330
return err
330331
}
331332
defer kv.Unlock(kvp)
332333

333334
alerts, err := kva.getResourceSpecificAlerts(resourceType, kv)
334335
if err != nil {
335-
dlog.Infof("Failed to get alerts of type %s, error: %s",
336+
logrus.Infof("Failed to get alerts of type %s, error: %s",
336337
resourceType, err.Error())
337338
return err
338339
}
@@ -469,18 +470,18 @@ func (kva *KvAlert) getKvdbForCluster(clusterID string) (kvdb.Kvdb, error) {
469470
}
470471

471472
func processWatchError(err error, watcherKey string, prefix string) error {
472-
dlog.Errorf("Alert Watch error for key %v: %v", watcherKey, err)
473+
logrus.Errorf("Alert Watch error for key %v: %v", watcherKey, err)
473474
w := watcherMap[watcherKey]
474475
w.status = watchError
475476
if w.watchErrors == 5 {
476-
dlog.Warnf("Too many watch errors for key (%v). Error: %s. Stopping the watch!!", watcherKey, err.Error())
477+
logrus.Warnf("Too many watch errors for key (%v). Error: %s. Stopping the watch!!", watcherKey, err.Error())
477478
w.cb(nil, api.AlertActionType_ALERT_ACTION_TYPE_NONE, prefix, "")
478479
// Too many watch errors. Stop the watch
479480
return err
480481
}
481482
w.watchErrors++
482483
if err := subscribeWatch(watcherKey); err != nil {
483-
dlog.Warnf("Failed to resubscribe alert watch for key: %s: %s", watcherKey, err.Error())
484+
logrus.Warnf("Failed to resubscribe alert watch for key: %s: %s", watcherKey, err.Error())
484485
}
485486
return err
486487
}

alert/alert_kvdb_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"github.com/libopenstorage/openstorage/pkg/proto/time"
1111
"github.com/portworx/kvdb"
1212
"github.com/portworx/kvdb/mem"
13+
"github.com/sirupsen/logrus"
1314
"github.com/stretchr/testify/require"
14-
"go.pedge.io/dlog"
1515
)
1616

1717
var (
@@ -45,7 +45,7 @@ func TestAll(t *testing.T) {
4545
func setup(t *testing.T) {
4646
kv := kvdb.Instance()
4747
if kv == nil {
48-
kv, err := kvdb.New(mem.Name, kvdbDomain+"/"+clusterName, []string{}, nil, dlog.Panicf)
48+
kv, err := kvdb.New(mem.Name, kvdbDomain+"/"+clusterName, []string{}, nil, logrus.Panicf)
4949
if err != nil {
5050
t.Fatalf("Failed to set default KV store : (%v): %v", mem.Name, err)
5151
}

api/flexvolume/flexvolume.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/libopenstorage/openstorage/volume"
1414
"github.com/libopenstorage/openstorage/volume/drivers"
1515

16-
"go.pedge.io/dlog"
16+
"github.com/sirupsen/logrus"
1717
)
1818

1919
const (
@@ -63,7 +63,7 @@ func (c *flexVolumeClient) Attach(jsonOptions map[string]string) error {
6363
func (c *flexVolumeClient) Detach(mountDevice string, options map[string]string) error {
6464
driverName, ok := deviceDriverMap[mountDevice]
6565
if !ok {
66-
dlog.Infof("Could not find driver for (%v). Resorting to default driver ", mountDevice)
66+
logrus.Infof("Could not find driver for (%v). Resorting to default driver ", mountDevice)
6767
driverName = c.defaultDriver
6868
}
6969
driver, err := c.getVolumeDriver(driverName)
@@ -96,7 +96,7 @@ func (c *flexVolumeClient) Mount(targetMountDir string, mountDevice string,
9696
// Update the deviceDriverMap
9797
mountManager, err := mount.New(mount.DeviceMount, nil, []string{""}, nil, []string{}, "")
9898
if err != nil {
99-
dlog.Infof("Could not read mountpoints from /proc/self/mountinfo. Device - Driver mapping not saved!")
99+
logrus.Infof("Could not read mountpoints from /proc/self/mountinfo. Device - Driver mapping not saved!")
100100
return nil
101101
}
102102
sourcePath, err := mountManager.GetSourcePath(targetMountDir)
@@ -119,7 +119,7 @@ func (c *flexVolumeClient) Unmount(mountDir string, options map[string]string) e
119119
}
120120
driverName, ok := deviceDriverMap[mountDevice]
121121
if !ok {
122-
dlog.Infof("Could not find driver for (%v). Resorting to default driver. ", mountDevice)
122+
logrus.Infof("Could not find driver for (%v). Resorting to default driver. ", mountDevice)
123123
driverName = c.defaultDriver
124124
}
125125
driver, err := c.getVolumeDriver(driverName)
@@ -152,7 +152,7 @@ func StartFlexVolumeAPI(port uint16, defaultDriver string) error {
152152
}
153153
go func() {
154154
if err := grpcServer.Serve(listener); err != nil {
155-
dlog.Errorln(err.Error())
155+
logrus.Errorln(err.Error())
156156
}
157157
}()
158158
return nil

api/server/server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88
"path"
99

10-
"go.pedge.io/dlog"
10+
"github.com/sirupsen/logrus"
1111

1212
"github.com/gorilla/mux"
1313
)
@@ -141,15 +141,15 @@ func startServer(name string, sockBase string, port uint16, routes []*Route) err
141141
os.Remove(socket)
142142
os.MkdirAll(path.Dir(socket), 0755)
143143

144-
dlog.Printf("Starting REST service on socket : %+v", socket)
144+
logrus.Printf("Starting REST service on socket : %+v", socket)
145145
listener, err = net.Listen("unix", socket)
146146
if err != nil {
147-
dlog.Warnln("Cannot listen on UNIX socket: ", err)
147+
logrus.Warnln("Cannot listen on UNIX socket: ", err)
148148
return err
149149
}
150150
go http.Serve(listener, router)
151151
if port != 0 {
152-
dlog.Printf("Starting REST service on port : %v", port)
152+
logrus.Printf("Starting REST service on port : %v", port)
153153
go http.ListenAndServe(fmt.Sprintf(":%d", port), router)
154154
}
155155
return nil
@@ -158,7 +158,7 @@ func startServer(name string, sockBase string, port uint16, routes []*Route) err
158158
type restServer interface {
159159
Routes() []*Route
160160
String() string
161-
logRequest(request string, id string) dlog.Logger
161+
logRequest(request string, id string) *logrus.Entry
162162
sendError(request string, id string, w http.ResponseWriter, msg string, code int)
163163
}
164164

@@ -168,8 +168,8 @@ type restBase struct {
168168
name string
169169
}
170170

171-
func (rest *restBase) logRequest(request string, id string) dlog.Logger {
172-
return dlog.WithFields(map[string]interface{}{
171+
func (rest *restBase) logRequest(request string, id string) *logrus.Entry {
172+
return logrus.WithFields(map[string]interface{}{
173173
"Driver": rest.name,
174174
"Request": request,
175175
"ID": id,
@@ -181,6 +181,6 @@ func (rest *restBase) sendError(request string, id string, w http.ResponseWriter
181181
}
182182

183183
func notFound(w http.ResponseWriter, r *http.Request) {
184-
dlog.Warnf("Not found: %+v ", r.URL)
184+
logrus.Warnf("Not found: %+v ", r.URL)
185185
http.NotFound(w, r)
186186
}

api/testing/testing_test.go

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

8-
"go.pedge.io/dlog"
8+
"github.com/sirupsen/logrus"
99

1010
"github.com/libopenstorage/openstorage/api"
1111
volumeclient "github.com/libopenstorage/openstorage/api/client/volume"
@@ -21,7 +21,7 @@ var (
2121
)
2222

2323
func init() {
24-
dlog.SetLevel(dlog.LevelDebug)
24+
logrus.SetLevel(logrus.DebugLevel)
2525
}
2626

2727
func makeRequest(t *testing.T) {

cluster/database.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"strings"
77

8-
"go.pedge.io/dlog"
8+
"github.com/sirupsen/logrus"
99

1010
"github.com/libopenstorage/openstorage/api"
1111
"github.com/portworx/kvdb"
@@ -28,19 +28,19 @@ func snapAndReadClusterInfo() (*ClusterInitState, error) {
2828
)
2929
for i := 0; i < 3; i++ {
3030
if i > 0 {
31-
dlog.Infof("Retrying snapshot")
31+
logrus.Infof("Retrying snapshot")
3232
}
3333
// Start the watch before the snapshot
3434
collector, err = kvdb.NewUpdatesCollector(kv, "", 0)
3535
if err != nil {
36-
dlog.Errorf("Failed to start collector for cluster db: %v", err)
36+
logrus.Errorf("Failed to start collector for cluster db: %v", err)
3737
collector = nil
3838
continue
3939
}
4040
// Create the snapshot
4141
snap, version, err = kv.Snapshot("")
4242
if err != nil {
43-
dlog.Errorf("Snapshot failed for cluster db: %v", err)
43+
logrus.Errorf("Snapshot failed for cluster db: %v", err)
4444
collector.Stop()
4545
collector = nil
4646
} else {
@@ -50,11 +50,11 @@ func snapAndReadClusterInfo() (*ClusterInitState, error) {
5050
if err != nil {
5151
return nil, err
5252
}
53-
dlog.Infof("Cluster db snapshot at: %v", version)
53+
logrus.Infof("Cluster db snapshot at: %v", version)
5454

5555
clusterDB, err := snap.Get(ClusterDBKey)
5656
if err != nil && !strings.Contains(err.Error(), "Key not found") {
57-
dlog.Warnln("Warning, could not read cluster database")
57+
logrus.Warnln("Warning, could not read cluster database")
5858
return nil, err
5959
}
6060

@@ -70,11 +70,11 @@ func snapAndReadClusterInfo() (*ClusterInitState, error) {
7070
}
7171

7272
if clusterDB == nil || bytes.Compare(clusterDB.Value, []byte("{}")) == 0 {
73-
dlog.Infoln("Cluster is uninitialized...")
73+
logrus.Infoln("Cluster is uninitialized...")
7474
return state, nil
7575
}
7676
if err := json.Unmarshal(clusterDB.Value, &db); err != nil {
77-
dlog.Warnln("Fatal, Could not parse cluster database ", kv)
77+
logrus.Warnln("Fatal, Could not parse cluster database ", kv)
7878
return state, err
7979
}
8080

@@ -91,16 +91,16 @@ func readClusterInfo() (ClusterInfo, uint64, error) {
9191
kv, err := kvdb.Get(ClusterDBKey)
9292

9393
if err != nil && !strings.Contains(err.Error(), "Key not found") {
94-
dlog.Warnln("Warning, could not read cluster database")
94+
logrus.Warnln("Warning, could not read cluster database")
9595
return db, 0, err
9696
}
9797

9898
if kv == nil || bytes.Compare(kv.Value, []byte("{}")) == 0 {
99-
dlog.Infoln("Cluster is uninitialized...")
99+
logrus.Infoln("Cluster is uninitialized...")
100100
return db, 0, nil
101101
}
102102
if err := json.Unmarshal(kv.Value, &db); err != nil {
103-
dlog.Warnln("Fatal, Could not parse cluster database ", kv)
103+
logrus.Warnln("Fatal, Could not parse cluster database ", kv)
104104
return db, 0, err
105105
}
106106

@@ -111,13 +111,13 @@ func writeClusterInfo(db *ClusterInfo) (*kvdb.KVPair, error) {
111111
kvdb := kvdb.Instance()
112112
b, err := json.Marshal(db)
113113
if err != nil {
114-
dlog.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
114+
logrus.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
115115
return nil, err
116116
}
117117

118118
kvp, err := kvdb.Put(ClusterDBKey, b, 0)
119119
if err != nil {
120-
dlog.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
120+
logrus.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
121121
return nil, err
122122
}
123123
return kvp, nil

0 commit comments

Comments
 (0)