Skip to content

Commit d077a85

Browse files
committed
better log format suggestion
1 parent fcf6b72 commit d077a85

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/handler/loki.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func getLokiError(resp []byte, code int) string {
7373
}
7474
err := json.Unmarshal(resp, &f)
7575
if err != nil {
76-
hlog.Errorf("Cannot unmarshal (%v). Response was: %s", err, string(resp))
76+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
7777
return fmt.Sprintf("Unknown error from Loki\ncannot unmarshal\n%s", resp)
7878
}
7979
message, ok := f["message"]
@@ -116,7 +116,7 @@ func fetchSingle(lokiClient httpclient.Caller, flowsURL string, merger loki.Merg
116116
}
117117
var qr model.QueryResponse
118118
if err := json.Unmarshal(resp, &qr); err != nil {
119-
hlog.Errorf("Cannot unmarshal (%v). Response was: %s", err, string(resp))
119+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
120120
return http.StatusInternalServerError, err
121121
}
122122
if _, err := merger.Add(qr.Data); err != nil {
@@ -148,7 +148,7 @@ func fetchParallel(lokiClient httpclient.Caller, queries []string, merger loki.M
148148
var qr model.QueryResponse
149149
err := json.Unmarshal(resp, &qr)
150150
if err != nil {
151-
hlog.Errorf("Cannot unmarshal (%v). Response was: %s", err, string(resp))
151+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
152152
errChan <- errorWithCode{err: err, code: http.StatusInternalServerError}
153153
} else {
154154
resChan <- qr
@@ -243,7 +243,7 @@ func LokiConfig(cfg *loki.Config, param string) func(w http.ResponseWriter, r *h
243243
cfg := make(map[string]interface{})
244244
err = yaml.Unmarshal(resp, &cfg)
245245
if err != nil {
246-
hlog.Errorf("Cannot unmarshal (%v). Response was: %s", err, string(resp))
246+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
247247
writeError(w, code, err.Error())
248248
return
249249
}

pkg/handler/resources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func getNamesForPrefix(cfg *loki.Config, lokiClient httpclient.Caller, prefix, k
137137
var qr model.QueryResponse
138138
err = json.Unmarshal(resp, &qr)
139139
if err != nil {
140-
hlog.Errorf("Cannot unmarshal (%v). Response was: %s", err, string(resp))
140+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
141141
return nil, http.StatusInternalServerError, errors.New("Failed to unmarshal Loki response: " + err.Error())
142142
}
143143

0 commit comments

Comments
 (0)