Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit b281e57

Browse files
authored
Merge pull request #1056 from grafana/switch-to-logrus-no-fields
switch to logrus logging library
2 parents a186549 + c15f8fb commit b281e57

File tree

106 files changed

+3202
-1969
lines changed

Some content is hidden

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

106 files changed

+3202
-1969
lines changed

Gopkg.lock

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ unused-packages = true
3737
version = "1.10.1"
3838

3939
[[constraint]]
40-
name = "github.com/Sirupsen/logrus"
41-
version = "0.7.3"
40+
name = "github.com/sirupsen/logrus"
41+
version = "1.0.6"
4242

4343
[[constraint]]
4444
name = "github.com/alyu/configparser"
@@ -128,10 +128,6 @@ unused-packages = true
128128
name = "github.com/raintank/schema"
129129
branch = "deprecate-gopkg-in"
130130

131-
[[constraint]]
132-
name = "github.com/raintank/worldping-api"
133-
revision = "66b28f1160d1e0d7d236b5bd96a5d8eee627357c"
134-
135131
[[constraint]]
136132
name = "github.com/rakyll/globalconf"
137133
branch = "master"

api/api.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ import (
1616
"github.com/grafana/metrictank/mdata/cache"
1717
"github.com/grafana/metrictank/stats"
1818
opentracing "github.com/opentracing/opentracing-go"
19-
"github.com/raintank/worldping-api/pkg/log"
19+
log "github.com/sirupsen/logrus"
2020
"gopkg.in/macaron.v1"
2121
)
2222

23-
var LogLevel int
24-
2523
var (
2624
// metric api.get_target is how long it takes to get a target
2725
getTargetDuration = stats.NewLatencyHistogram15s32("api.get_target")
@@ -113,12 +111,12 @@ func (s *Server) Run() {
113111
if s.SSL {
114112
proto = "https"
115113
}
116-
log.Info("API Listening on: %v://%s/", proto, s.Addr)
114+
log.Infof("API Listening on: %v://%s/", proto, s.Addr)
117115

118116
// define our own listner so we can call Close on it
119117
l, err := net.Listen("tcp", s.Addr)
120118
if err != nil {
121-
log.Fatal(4, "API failed to listen on %s, %s", s.Addr, err.Error())
119+
log.Fatalf("API failed to listen on %s, %s", s.Addr, err.Error())
122120
}
123121
go s.handleShutdown(l)
124122
srv := http.Server{
@@ -129,7 +127,7 @@ func (s *Server) Run() {
129127
var cert tls.Certificate
130128
cert, err = tls.LoadX509KeyPair(s.certFile, s.keyFile)
131129
if err != nil {
132-
log.Fatal(4, "API Failed to start server: %v", err)
130+
log.Fatalf("API Failed to start server: %v", err)
133131
}
134132
srv.TLSConfig = &tls.Config{
135133
Certificates: []tls.Certificate{cert},
@@ -142,7 +140,7 @@ func (s *Server) Run() {
142140
}
143141

144142
if err != nil {
145-
log.Info("API %s", err.Error())
143+
log.Infof("API %s", err.Error())
146144
}
147145
}
148146

api/ccache.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/grafana/metrictank/api/response"
1212
"github.com/grafana/metrictank/cluster"
1313
"github.com/grafana/metrictank/idx"
14-
"github.com/raintank/worldping-api/pkg/log"
14+
log "github.com/sirupsen/logrus"
1515
)
1616

1717
func (s *Server) ccacheDelete(ctx *middleware.Context, req models.CCacheDelete) {
@@ -109,18 +109,18 @@ func (s *Server) ccacheDeletePropagate(ctx context.Context, req *models.CCacheDe
109109
func (s *Server) ccacheDeleteRemote(ctx context.Context, req *models.CCacheDelete, peer cluster.Node) models.CCacheDeleteResp {
110110
var res models.CCacheDeleteResp
111111

112-
log.Debug("HTTP metricDelete calling %s/ccache/delete", peer.GetName())
112+
log.Debugf("HTTP metricDelete calling %s/ccache/delete", peer.GetName())
113113
buf, err := peer.Post(ctx, "ccacheDeleteRemote", "/ccache/delete", *req)
114114
if err != nil {
115-
log.Error(4, "HTTP ccacheDelete error querying %s/ccache/delete: %q", peer.GetName(), err)
115+
log.Errorf("HTTP ccacheDelete error querying %s/ccache/delete: %q", peer.GetName(), err.Error())
116116
res.FirstError = err.Error()
117117
res.Errors++
118118
return res
119119
}
120120

121121
err = json.Unmarshal(buf, &res)
122122
if err != nil {
123-
log.Error(4, "HTTP ccacheDelete error unmarshaling body from %s/ccache/delete: %q", peer.GetName(), err)
123+
log.Errorf("HTTP ccacheDelete error unmarshaling body from %s/ccache/delete: %q", peer.GetName(), err.Error())
124124
res.FirstError = err.Error()
125125
res.Errors++
126126
}

api/cluster.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/grafana/metrictank/api/response"
1515
"github.com/grafana/metrictank/cluster"
1616
"github.com/grafana/metrictank/stats"
17-
"github.com/raintank/worldping-api/pkg/log"
17+
log "github.com/sirupsen/logrus"
1818
"github.com/tinylib/msgp/msgp"
1919
)
2020

@@ -210,7 +210,7 @@ func (s *Server) getData(ctx *middleware.Context, request models.GetData) {
210210
if err != nil {
211211
// the only errors returned are from us catching panics, so we should treat them
212212
// all as internalServerErrors
213-
log.Error(3, "HTTP getData() %s", err.Error())
213+
log.Errorf("HTTP getData() %s", err.Error())
214214
response.Write(ctx, response.WrapError(err))
215215
return
216216
}
@@ -252,11 +252,11 @@ func (s *Server) peerQuery(ctx context.Context, data cluster.Traceable, name, pa
252252
} else {
253253
peers, err = cluster.MembersForQuery()
254254
if err != nil {
255-
log.Error(3, "HTTP peerQuery unable to get peers, %s", err)
255+
log.Errorf("HTTP peerQuery unable to get peers, %s", err.Error())
256256
return nil, err
257257
}
258258
}
259-
log.Debug("HTTP %s across %d instances", name, len(peers)-1)
259+
log.Debugf("HTTP %s across %d instances", name, len(peers)-1)
260260

261261
reqCtx, cancel := context.WithCancel(ctx)
262262
defer cancel()
@@ -273,11 +273,11 @@ func (s *Server) peerQuery(ctx context.Context, data cluster.Traceable, name, pa
273273
wg.Add(1)
274274
go func(peer cluster.Node) {
275275
defer wg.Done()
276-
log.Debug("HTTP Render querying %s%s", peer.GetName(), path)
276+
log.Debugf("HTTP Render querying %s%s", peer.GetName(), path)
277277
buf, err := peer.Post(reqCtx, name, path, data)
278278
if err != nil {
279279
cancel()
280-
log.Error(4, "HTTP Render error querying %s%s: %q", peer.GetName(), path, err)
280+
log.Errorf("HTTP Render error querying %s%s: %q", peer.GetName(), path, err.Error())
281281
}
282282
responses <- struct {
283283
data PeerResponse
@@ -314,10 +314,10 @@ func (s *Server) peerQuery(ctx context.Context, data cluster.Traceable, name, pa
314314
func (s *Server) peerQuerySpeculative(ctx context.Context, data cluster.Traceable, name, path string) (map[string]PeerResponse, error) {
315315
peerGroups, err := cluster.MembersForSpeculativeQuery()
316316
if err != nil {
317-
log.Error(3, "HTTP peerQuery unable to get peers, %s", err)
317+
log.Errorf("HTTP peerQuery unable to get peers, %s", err.Error())
318318
return nil, err
319319
}
320-
log.Debug("HTTP %s across %d instances", name, len(peerGroups)-1)
320+
log.Debugf("HTTP %s across %d instances", name, len(peerGroups)-1)
321321

322322
reqCtx, cancel := context.WithCancel(ctx)
323323
defer cancel()
@@ -332,7 +332,7 @@ func (s *Server) peerQuerySpeculative(ctx context.Context, data cluster.Traceabl
332332
}, 1)
333333

334334
askPeer := func(shardGroup int32, peer cluster.Node) {
335-
log.Debug("HTTP Render querying %s%s", peer.GetName(), path)
335+
log.Debugf("HTTP Render querying %s%s", peer.GetName(), path)
336336
buf, err := peer.Post(reqCtx, name, path, data)
337337

338338
select {
@@ -344,7 +344,7 @@ func (s *Server) peerQuerySpeculative(ctx context.Context, data cluster.Traceabl
344344

345345
if err != nil {
346346
cancel()
347-
log.Error(4, "HTTP Render error querying %s%s: %q", peer.GetName(), path, err)
347+
log.Errorf("HTTP Render error querying %s%s: %q", peer.GetName(), path, err.Error())
348348
}
349349
responses <- struct {
350350
shardGroup int32

api/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"time"
99

1010
"github.com/raintank/dur"
11-
"github.com/raintank/worldping-api/pkg/log"
1211
"github.com/rakyll/globalconf"
12+
log "github.com/sirupsen/logrus"
1313
)
1414

1515
var (
@@ -61,12 +61,12 @@ func ConfigProcess() {
6161
//validate the addr
6262
_, err := net.ResolveTCPAddr("tcp", Addr)
6363
if err != nil {
64-
log.Fatal(4, "API listen address is not a valid TCP address.")
64+
log.Fatal("API listen address is not a valid TCP address.")
6565
}
6666

6767
u, err := url.Parse(fallbackGraphite)
6868
if err != nil {
69-
log.Fatal(4, "API Cannot parse fallback-graphite-addr: %s", err)
69+
log.Fatalf("API Cannot parse fallback-graphite-addr: %s", err.Error())
7070
}
7171
graphiteProxy = NewGraphiteProxy(u)
7272

@@ -75,7 +75,7 @@ func ConfigProcess() {
7575
} else {
7676
timeZone, err = time.LoadLocation(timeZoneStr)
7777
if err != nil {
78-
log.Fatal(4, "API Cannot load timezone %q: %s", timeZoneStr, err)
78+
log.Fatalf("API Cannot load timezone %q: %s", timeZoneStr, err.Error())
7979
}
8080
}
8181
}

0 commit comments

Comments
 (0)